Skip to content

Commit aea363c

Browse files
committed
Fix pytest.raises in tests
1 parent dc4e9cc commit aea363c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/test_importer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44

55

66
def test_invalid_format():
7-
with pytest.raises(ImportFromStringError) as exc:
7+
with pytest.raises(ImportFromStringError) as exc_info:
88
import_from_string("example:")
99
expected = 'Import string "example:" must be in format "<module>:<attribute>".'
10-
assert expected in str(exc)
10+
assert expected in str(exc_info.value)
1111

1212

1313
def test_invalid_module():
14-
with pytest.raises(ImportFromStringError) as exc:
14+
with pytest.raises(ImportFromStringError) as exc_info:
1515
import_from_string("module_does_not_exist:myattr")
1616
expected = 'Could not import module "module_does_not_exist".'
17-
assert expected in str(exc)
17+
assert expected in str(exc_info.value)
1818

1919

2020
def test_invalid_attr():
21-
with pytest.raises(ImportFromStringError) as exc:
21+
with pytest.raises(ImportFromStringError) as exc_info:
2222
import_from_string("tempfile:attr_does_not_exist")
2323
expected = 'Attribute "attr_does_not_exist" not found in module "tempfile".'
24-
assert expected in str(exc)
24+
assert expected in str(exc_info.value)
2525

2626

2727
def test_internal_import_error():
28-
with pytest.raises(ImportError) as exc:
28+
with pytest.raises(ImportError):
2929
import_from_string("tests.importer.raise_import_error:myattr")
3030

3131

0 commit comments

Comments
 (0)