mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-03 12:50:06 +06:00
Fix test isolation for clear_import_cache utility (#36345)
* test fixup * test fixup * fixing tests for unused imports * style fixes * fix * style fixes * styke fix * remove isolated module cache * rm custom subprocess defination * run using exsiting fn * style fixup * make fixup * remove redundant comments * rm redundat skipif + style changes
This commit is contained in:
parent
27361bd218
commit
8e67230860
@ -1,23 +1,26 @@
|
||||
import sys
|
||||
|
||||
from transformers.testing_utils import run_test_using_subprocess
|
||||
from transformers.utils.import_utils import clear_import_cache
|
||||
|
||||
|
||||
@run_test_using_subprocess
|
||||
def test_clear_import_cache():
|
||||
# Import some transformers modules
|
||||
"""Test the clear_import_cache function."""
|
||||
|
||||
# Get initial module count
|
||||
# Save initial state
|
||||
initial_modules = {name: mod for name, mod in sys.modules.items() if name.startswith("transformers.")}
|
||||
assert len(initial_modules) > 0, "No transformers modules loaded before test"
|
||||
|
||||
# Verify we have some modules loaded
|
||||
assert len(initial_modules) > 0
|
||||
|
||||
# Clear cache
|
||||
# Execute clear_import_cache() function
|
||||
clear_import_cache()
|
||||
|
||||
# Check modules were removed
|
||||
# Verify modules were removed
|
||||
remaining_modules = {name: mod for name, mod in sys.modules.items() if name.startswith("transformers.")}
|
||||
assert len(remaining_modules) < len(initial_modules)
|
||||
assert len(remaining_modules) < len(initial_modules), "No modules were removed"
|
||||
|
||||
# Verify we can reimport
|
||||
assert "transformers" in sys.modules
|
||||
# Import and verify module exists
|
||||
from transformers.models.auto import modeling_auto
|
||||
|
||||
assert "transformers.models.auto.modeling_auto" in sys.modules
|
||||
assert modeling_auto.__name__ == "transformers.models.auto.modeling_auto"
|
||||
|
Loading…
Reference in New Issue
Block a user