bpo-30876: Relative import from unloaded package now reimports the pa… · python/cpython@8a9cd20 (original) (raw)
`@@ -23,8 +23,9 @@
`
23
23
`EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython,
`
24
24
`make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask,
`
25
25
`unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE,
`
26
``
`-
temp_dir)
`
``
26
`+
temp_dir, DirsOnSysPath)
`
27
27
`from test.support import script_helper
`
``
28
`+
from test.test_importlib.util import uncache
`
28
29
``
29
30
``
30
31
`skip_if_dont_write_bytecode = unittest.skipIf(
`
`@@ -670,11 +671,11 @@ def check_relative():
`
670
671
``
671
672
`# Check relative import fails with only package wrong
`
672
673
`ns = dict(package='foo', name='test.notarealmodule')
`
673
``
`-
self.assertRaises(SystemError, check_relative)
`
``
674
`+
self.assertRaises(ModuleNotFoundError, check_relative)
`
674
675
``
675
676
`# Check relative import fails with package and name wrong
`
676
677
`ns = dict(package='foo', name='notarealpkg.notarealmodule')
`
677
``
`-
self.assertRaises(SystemError, check_relative)
`
``
678
`+
self.assertRaises(ModuleNotFoundError, check_relative)
`
678
679
``
679
680
`# Check relative import fails with package set to a non-string
`
680
681
`ns = dict(package=object())
`
`@@ -689,6 +690,20 @@ def test_absolute_import_without_future(self):
`
689
690
`self.fail("explicit relative import triggered an "
`
690
691
`"implicit absolute import")
`
691
692
``
``
693
`+
def test_import_from_non_package(self):
`
``
694
`+
path = os.path.join(os.path.dirname(file), 'data', 'package2')
`
``
695
`+
with uncache('submodule1', 'submodule2'), DirsOnSysPath(path):
`
``
696
`+
with self.assertRaises(ImportError):
`
``
697
`+
import submodule1
`
``
698
`+
self.assertNotIn('submodule1', sys.modules)
`
``
699
`+
self.assertNotIn('submodule2', sys.modules)
`
``
700
+
``
701
`+
def test_import_from_unloaded_package(self):
`
``
702
`+
with uncache('package2', 'package2.submodule1', 'package2.submodule2'), \
`
``
703
`+
DirsOnSysPath(os.path.join(os.path.dirname(file), 'data')):
`
``
704
`+
import package2.submodule1
`
``
705
`+
package2.submodule1.submodule2
`
``
706
+
692
707
``
693
708
`class OverridingImportBuiltinTests(unittest.TestCase):
`
694
709
`def test_override_builtin(self):
`