Skip to content

Commit 76158ba

Browse files
committed
test: __getattr__ returned by __attach__, error_on_import
1 parent 7b6c02b commit 76158ba

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_lazy_loader.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ def test_lazy_attach():
123123
if v is not None:
124124
assert locls[k] == v
125125

126+
# Exercise __getattr__, though it will just error
127+
with pytest.raises(ImportError):
128+
locls["__getattr__"]("mysubmodule")
129+
130+
# Attribute is supposed to be imported, error on submodule load
131+
with pytest.raises(ImportError):
132+
locls["__getattr__"]("some_var_or_func")
133+
134+
# Attribute is unknown, raise AttributeError
135+
with pytest.raises(AttributeError):
136+
locls["__getattr__"]("unknown_attr")
137+
126138

127139
def test_lazy_attach_returns_copies():
128140
_get, _dir, _all = lazy.attach(
@@ -222,6 +234,10 @@ def test_require_kwarg():
222234
math = lazy.load("math", require="somepkg >= 2.0")
223235
assert isinstance(math, lazy.DelayedImportErrorModule)
224236

237+
# Eager failure
238+
with pytest.raises(ModuleNotFoundError):
239+
lazy.load("math", require="somepkg >= 2.0", error_on_import=True)
240+
225241
# When a module can be loaded but the version can't be checked,
226242
# raise a ValueError
227243
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)