Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76158ba

Browse filesBrowse files
committed
test: __getattr__ returned by __attach__, error_on_import
1 parent 7b6c02b commit 76158ba
Copy full SHA for 76158ba

File tree

Expand file treeCollapse file tree

1 file changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-0
lines changed

‎tests/test_lazy_loader.py

Copy file name to clipboardExpand all lines: tests/test_lazy_loader.py
+16Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.