File tree 4 files changed +19
-1
lines changed 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Used by test_importer.py
2
+ from .circular_import_b import foo # noqa
3
+
4
+ bar = 123
Original file line number Diff line number Diff line change
1
+ # Used by test_importer.py
2
+ from .circular_import_a import bar # noqa
3
+
4
+ foo = 123
Original file line number Diff line number Diff line change @@ -41,3 +41,13 @@ def test_no_import_needed() -> None:
41
41
42
42
instance = import_from_string (TemporaryFile )
43
43
assert instance == TemporaryFile
44
+
45
+
46
+ def test_circular_import_error () -> None :
47
+ with pytest .raises (ImportError ) as exc_info :
48
+ import_from_string ("tests.importer.circular_import_a:bar" )
49
+ expected = (
50
+ "cannot import name 'bar' from partially initialized module "
51
+ "'tests.importer.circular_import_a' (most likely due to a circular import)"
52
+ )
53
+ assert expected in str (exc_info .value )
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ def import_from_string(import_str: Any) -> Any:
19
19
20
20
try :
21
21
module = importlib .import_module (module_str )
22
- except ImportError as exc :
22
+ except ModuleNotFoundError as exc :
23
23
if exc .name != module_str :
24
24
raise exc from None
25
25
message = 'Could not import module "{module_str}".'
You can’t perform that action at this time.
0 commit comments