mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-108927: Fix removing testing modules from sys.modules (GH-108952)
It breaks import machinery if the test module has submodules used in other tests.
This commit is contained in:
parent
c718ab92a5
commit
e08b70fab1
8 changed files with 67 additions and 9 deletions
|
@ -2031,6 +2031,25 @@ class ArgsTestCase(BaseTestCase):
|
|||
self.check_executed_tests(output, tests,
|
||||
stats=len(tests), parallel=True)
|
||||
|
||||
def test_unload_tests(self):
|
||||
# Test that unloading test modules does not break tests
|
||||
# that import from other tests.
|
||||
# The test execution order matters for this test.
|
||||
# Both test_regrtest_a and test_regrtest_c which are executed before
|
||||
# and after test_regrtest_b import a submodule from the test_regrtest_b
|
||||
# package and use it in testing. test_regrtest_b itself does not import
|
||||
# that submodule.
|
||||
# Previously test_regrtest_c failed because test_regrtest_b.util in
|
||||
# sys.modules was left after test_regrtest_a (making the import
|
||||
# statement no-op), but new test_regrtest_b without the util attribute
|
||||
# was imported for test_regrtest_b.
|
||||
testdir = os.path.join(os.path.dirname(__file__),
|
||||
'regrtestdata', 'import_from_tests')
|
||||
tests = [f'test_regrtest_{name}' for name in ('a', 'b', 'c')]
|
||||
args = ['-Wd', '-E', '-bb', '-m', 'test', '--testdir=%s' % testdir, *tests]
|
||||
output = self.run_python(args)
|
||||
self.check_executed_tests(output, tests, stats=3)
|
||||
|
||||
def check_add_python_opts(self, option):
|
||||
# --fast-ci and --slow-ci add "-u -W default -bb -E" options to Python
|
||||
code = textwrap.dedent(r"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue