diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-10-30 11:19:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 11:19:51 (GMT) |
commit | 3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e (patch) | |
tree | 6e84750ed25ac0ec74e491a4261ce4338bff4fa0 /Lib/test/test_import | |
parent | 95b6acf951fa7f503a3cc5ce7d969d7bcf2f95c9 (diff) | |
download | cpython-3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e.zip cpython-3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e.tar.gz cpython-3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e.tar.bz2 |
bpo-33237: Improve AttributeError message for partially initialized module. (GH-6398)
Diffstat (limited to 'Lib/test/test_import')
-rw-r--r-- | Lib/test/test_import/__init__.py | 13 | ||||
-rw-r--r-- | Lib/test/test_import/data/circular_imports/source.py | 2 | ||||
-rw-r--r-- | Lib/test/test_import/data/circular_imports/use.py | 2 |
3 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index fb9453a..7306e0f 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -1271,6 +1271,19 @@ class CircularImportTests(unittest.TestCase): except ImportError: self.fail('circular import with binding a submodule to a name failed') + def test_crossreference1(self): + import test.test_import.data.circular_imports.use + import test.test_import.data.circular_imports.source + + def test_crossreference2(self): + with self.assertRaises(AttributeError) as cm: + import test.test_import.data.circular_imports.source + errmsg = str(cm.exception) + self.assertIn('test.test_import.data.circular_imports.source', errmsg) + self.assertIn('spam', errmsg) + self.assertIn('partially initialized module', errmsg) + self.assertIn('circular import', errmsg) + if __name__ == '__main__': # Test needs to be a package, so we can do relative imports. diff --git a/Lib/test/test_import/data/circular_imports/source.py b/Lib/test/test_import/data/circular_imports/source.py new file mode 100644 index 0000000..f104099 --- /dev/null +++ b/Lib/test/test_import/data/circular_imports/source.py @@ -0,0 +1,2 @@ +from . import use +spam = 1 diff --git a/Lib/test/test_import/data/circular_imports/use.py b/Lib/test/test_import/data/circular_imports/use.py new file mode 100644 index 0000000..418f9e2 --- /dev/null +++ b/Lib/test/test_import/data/circular_imports/use.py @@ -0,0 +1,2 @@ +from . import source +source.spam |