File tree 1 file changed +21
-4
lines changed
1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 16
16
)
17
17
18
18
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
+
19
35
@pytest .fixture
20
36
def client ():
21
37
with mock .patch ("replicate.Client" ) as client_class :
@@ -111,10 +127,11 @@ def test_find_api_token_from_context(client):
111
127
112
128
113
129
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 ()
118
135
119
136
120
137
def test_include_outside_load_state ():
You can’t perform that action at this time.
0 commit comments