Skip to content

Commit f1e7442

Browse files
Wauplintestbot
andauthored
Remove set_access_token usage + fail tests if FutureWarning (#5623)
* Remove set_access_token usage + fail tests if FutureWarning * Error only on huggingface_hub future warnings * fix tests --------- Co-authored-by: testbot <[email protected]>
1 parent dd31bce commit f1e7442

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
license_file = LICENSE
33

44
[tool:pytest]
5+
# Test fails if a FutureWarning is thrown by `huggingface_hub`
6+
filterwarnings =
7+
error::FutureWarning:huggingface_hub*
58
markers =
69
unit: unit test
710
integration: integration test

tests/fixtures/hub.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ def ci_hub_token_path(monkeypatch):
3939

4040
@pytest.fixture
4141
def set_ci_hub_access_token(ci_hub_config, ci_hub_token_path):
42-
_api = HfApi(endpoint=CI_HUB_ENDPOINT)
43-
_api.set_access_token(CI_HUB_USER_TOKEN)
4442
HfFolder.save_token(CI_HUB_USER_TOKEN)
4543
yield
4644
HfFolder.delete_token()
47-
_api.unset_access_token()
4845

4946

5047
@pytest.fixture(scope="session")
@@ -54,14 +51,11 @@ def hf_api():
5451

5552
@pytest.fixture(scope="session")
5653
def hf_token(hf_api: HfApi):
57-
hf_api.set_access_token(CI_HUB_USER_TOKEN)
54+
previous_token = HfFolder.get_token()
5855
HfFolder.save_token(CI_HUB_USER_TOKEN)
59-
6056
yield CI_HUB_USER_TOKEN
61-
try:
62-
hf_api.unset_access_token()
63-
except requests.exceptions.HTTPError:
64-
pass
57+
if previous_token is not None:
58+
HfFolder.save_token(previous_token)
6559

6660

6761
@pytest.fixture

0 commit comments

Comments
 (0)