MCPcopy Create free account
hub / github.com/dateutil/dateutil / clean_import

Function clean_import

tests/test_imports.py:12–36  ·  view source on GitHub ↗

Create a somewhat clean import base for lazy import tests

()

Source from the content-addressed store, hash-verified

10
11@pytest.fixture(scope="function")
12def clean_import():
13 """Create a somewhat clean import base for lazy import tests"""
14 du_modules = {
15 mod_name: mod
16 for mod_name, mod in sys.modules.items()
17 if mod_name.startswith("dateutil")
18 }
19
20 other_modules = {
21 mod_name for mod_name in sys.modules if mod_name not in du_modules
22 }
23
24 for mod_name in du_modules:
25 del sys.modules[mod_name]
26
27 yield
28
29 # Delete anything that wasn't in the origin sys.modules list
30 for mod_name in list(sys.modules):
31 if mod_name not in other_modules:
32 del sys.modules[mod_name]
33
34 # Restore original modules
35 for mod_name, mod in du_modules.items():
36 sys.modules[mod_name] = mod
37
38
39@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected