Skip to content

Commit beeb504

Browse files
committed
Update sys.modules test
1 parent 9be4afb commit beeb504

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/test_lazy_loader.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ def test_import_error():
2121
import anything_not_real # noqa: F401
2222

2323

24-
def test_lazy_import_impact_on_sys_modules():
25-
math = lazy.load("math")
26-
anything_not_real = lazy.load("anything_not_real")
24+
def test_builtin_is_in_sys_modules():
25+
with lazy_import():
26+
import math
27+
28+
assert isinstance(math, types.ModuleType)
29+
assert "math" in sys.modules
30+
31+
math.pi # trigger load of math
2732

2833
assert isinstance(math, types.ModuleType)
2934
assert "math" in sys.modules
30-
assert isinstance(anything_not_real, lazy.DelayedImportErrorModule)
31-
assert "anything_not_real" not in sys.modules
3235

36+
37+
def test_non_builtin_is_in_sys_modules():
3338
# only do this if numpy is installed
3439
pytest.importorskip("numpy")
35-
np = lazy.load("numpy")
40+
with lazy_import():
41+
import numpy as np
42+
3643
assert isinstance(np, types.ModuleType)
3744
assert "numpy" in sys.modules
3845

0 commit comments

Comments
 (0)