-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that TensorFlow is not imported on startup (#904)
* test tf not imported on startup * add require_tf * better comment * Update test_import.py * add pytest ./tests/test_tf*
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
import unittest | ||
|
||
from huggingface_hub.file_download import is_tf_available | ||
|
||
|
||
def require_tf(test_case): | ||
""" | ||
Decorator marking a test that requires TensorFlow. | ||
These tests are skipped when TensorFlow is not installed. | ||
""" | ||
if not is_tf_available(): | ||
return unittest.skip("test requires Tensorflow")(test_case) | ||
else: | ||
return test_case | ||
|
||
|
||
@require_tf | ||
def test_import_huggingface_hub_doesnt_import_tensorfow(): | ||
# `import huggingface_hub` is not necessary since huggingface_hub is already imported at the top of this file, | ||
# but let's keep it here anyway just in case | ||
import huggingface_hub # noqa | ||
|
||
assert "tensorflow" not in sys.modules |