File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
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():
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
127139def 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 ):
You can’t perform that action at this time.
0 commit comments