File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Original file line number Diff line number Diff line change @@ -123,6 +123,18 @@ def test_lazy_attach():
123
123
if v is not None :
124
124
assert locls [k ] == v
125
125
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
+
126
138
127
139
def test_lazy_attach_returns_copies ():
128
140
_get , _dir , _all = lazy .attach (
@@ -222,6 +234,10 @@ def test_require_kwarg():
222
234
math = lazy .load ("math" , require = "somepkg >= 2.0" )
223
235
assert isinstance (math , lazy .DelayedImportErrorModule )
224
236
237
+ # Eager failure
238
+ with pytest .raises (ModuleNotFoundError ):
239
+ lazy .load ("math" , require = "somepkg >= 2.0" , error_on_import = True )
240
+
225
241
# When a module can be loaded but the version can't be checked,
226
242
# raise a ValueError
227
243
with pytest .raises (ValueError ):
You can’t perform that action at this time.
0 commit comments