bpo-20490: Improve circular import error message (GH-15308)

This commit is contained in:
Anthony Sottile 2019-09-09 08:17:50 -07:00 committed by Steve Dower
parent 88b24f96ae
commit 65366bc8bd
5 changed files with 27 additions and 4 deletions

View file

@ -1324,6 +1324,16 @@ class CircularImportTests(unittest.TestCase):
self.assertIn('partially initialized module', errmsg)
self.assertIn('circular import', errmsg)
def test_circular_from_import(self):
with self.assertRaises(ImportError) as cm:
import test.test_import.data.circular_imports.from_cycle1
self.assertIn(
"cannot import name 'b' from partially initialized module "
"'test.test_import.data.circular_imports.from_cycle1' "
"(most likely due to a circular import)",
str(cm.exception),
)
if __name__ == '__main__':
# Test needs to be a package, so we can do relative imports.

View file

@ -0,0 +1,2 @@
from .from_cycle2 import a
b = 1

View file

@ -0,0 +1,2 @@
from .from_cycle1 import b
a = 1