Skip to content

Commit 826fb7e

Browse files
committed
Automatically clear REPLICATE_API_TOKEN from test env
1 parent 8e6e5bf commit 826fb7e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tests/test_include.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
)
1717

1818

19+
@pytest.fixture(autouse=True)
20+
def no_api_token_in_env():
21+
"""
22+
Remove REPLICATE_API_TOKEN from environment during tests and restore it after.
23+
"""
24+
original_token = os.environ.get("REPLICATE_API_TOKEN")
25+
26+
if "REPLICATE_API_TOKEN" in os.environ:
27+
del os.environ["REPLICATE_API_TOKEN"]
28+
29+
yield
30+
31+
if original_token is not None:
32+
os.environ["REPLICATE_API_TOKEN"] = original_token
33+
34+
1935
@pytest.fixture
2036
def client():
2137
with mock.patch("replicate.Client") as client_class:
@@ -111,10 +127,11 @@ def test_find_api_token_from_context(client):
111127

112128

113129
def test_find_api_token_raises_error():
114-
with mock.patch.dict(os.environ, {}, clear=True):
115-
fn = Function("owner/model:version")
116-
with pytest.raises(ValueError, match="No run token found"):
117-
fn._client()
130+
assert "REPLICATE_API_TOKEN" not in os.environ
131+
132+
fn = Function("owner/model:version")
133+
with pytest.raises(ValueError, match="No run token found"):
134+
fn._client()
118135

119136

120137
def test_include_outside_load_state():

0 commit comments

Comments
 (0)