File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 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
2036def client ():
2137 with mock .patch ("replicate.Client" ) as client_class :
@@ -111,10 +127,11 @@ def test_find_api_token_from_context(client):
111127
112128
113129def 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
120137def test_include_outside_load_state ():
You can’t perform that action at this time.
0 commit comments