@@ -59,17 +59,21 @@ def test_write_action_use_auth_token_false(self) -> None:
5959 with self .assertRaises (ValueError ):
6060 build_hf_headers (use_auth_token = False , is_write_action = True )
6161
62- @patch .dict ("os.environ" , {"HF_HUB_DISABLE_IMPLICIT_TOKEN" : "1" })
6362 def test_implicit_use_disabled (self , mock_HfFolder : Mock ) -> None :
64- mock_HfFolder ().get_token .return_value = FAKE_TOKEN
65- self .assertEqual (build_hf_headers (), NO_AUTH_HEADER ) # token is not sent
63+ with patch ( # not as decorator to avoid friction with @handle_injection
64+ "huggingface_hub.utils._headers.HF_HUB_DISABLE_IMPLICIT_TOKEN" , True
65+ ):
66+ mock_HfFolder ().get_token .return_value = FAKE_TOKEN
67+ self .assertEqual (build_hf_headers (), NO_AUTH_HEADER ) # token is not sent
6668
67- @patch .dict ("os.environ" , {"HF_HUB_DISABLE_IMPLICIT_TOKEN" : "1" })
6869 def test_implicit_use_disabled_but_explicit_use (self , mock_HfFolder : Mock ) -> None :
69- mock_HfFolder ().get_token .return_value = FAKE_TOKEN
70+ with patch ( # not as decorator to avoid friction with @handle_injection
71+ "huggingface_hub.utils._headers.HF_HUB_DISABLE_IMPLICIT_TOKEN" , True
72+ ):
73+ mock_HfFolder ().get_token .return_value = FAKE_TOKEN
7074
71- # This is not an implicit use so we still send it
72- self .assertEqual (build_hf_headers (use_auth_token = True ), FAKE_TOKEN_HEADER )
75+ # This is not an implicit use so we still send it
76+ self .assertEqual (build_hf_headers (use_auth_token = True ), FAKE_TOKEN_HEADER )
7377
7478
7579class TestUserAgentHeadersUtil (unittest .TestCase ):
0 commit comments