Skip to content

Commit 2f99692

Browse files
committed
test: Use pytest.raises() checks
1 parent 8766873 commit 2f99692

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

tests/test_lazy_loader.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,12 @@ def test_lazy_import_basics():
3737
# Now test that accessing attributes does what it should
3838
assert math.sin(math.pi) == pytest.approx(0, 1e-6)
3939
# poor-mans pytest.raises for testing errors on attribute access
40-
try:
40+
with pytest.raises(ModuleNotFoundError):
4141
anything_not_real.pi
42-
raise AssertionError() # Should not get here
43-
except ModuleNotFoundError:
44-
pass
4542
assert isinstance(anything_not_real, lazy.DelayedImportErrorModule)
4643
# see if it changes for second access
47-
try:
44+
with pytest.raises(ModuleNotFoundError):
4845
anything_not_real.pi
49-
raise AssertionError() # Should not get here
50-
except ModuleNotFoundError:
51-
pass
5246

5347

5448
def test_lazy_import_subpackages():
@@ -88,11 +82,8 @@ def test_lazy_import_nonbuiltins():
8882
if not isinstance(np, lazy.DelayedImportErrorModule):
8983
assert np.sin(np.pi) == pytest.approx(0, 1e-6)
9084
if isinstance(sp, lazy.DelayedImportErrorModule):
91-
try:
85+
with pytest.raises(ModuleNotFoundError):
9286
sp.pi
93-
raise AssertionError()
94-
except ModuleNotFoundError:
95-
pass
9687

9788

9889
def test_lazy_attach():

0 commit comments

Comments
 (0)