forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-108927: Fix removing testing modules from sys.modules (pytho…
…nGH-108952) It breaks import machinery if the test module has submodules used in other tests.
- Loading branch information
1 parent
78c8faf
commit a096f48
Showing
8 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sys | ||
import unittest | ||
import test_regrtest_b.util | ||
|
||
class Test(unittest.TestCase): | ||
def test(self): | ||
test_regrtest_b.util # does not fail | ||
self.assertIn('test_regrtest_a', sys.modules) | ||
self.assertIs(sys.modules['test_regrtest_b'], test_regrtest_b) | ||
self.assertIs(sys.modules['test_regrtest_b.util'], test_regrtest_b.util) | ||
self.assertNotIn('test_regrtest_c', sys.modules) |
9 changes: 9 additions & 0 deletions
9
Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import sys | ||
import unittest | ||
|
||
class Test(unittest.TestCase): | ||
def test(self): | ||
self.assertNotIn('test_regrtest_a', sys.modules) | ||
self.assertIn('test_regrtest_b', sys.modules) | ||
self.assertNotIn('test_regrtest_b.util', sys.modules) | ||
self.assertNotIn('test_regrtest_c', sys.modules) |
Empty file.
11 changes: 11 additions & 0 deletions
11
Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sys | ||
import unittest | ||
import test_regrtest_b.util | ||
|
||
class Test(unittest.TestCase): | ||
def test(self): | ||
test_regrtest_b.util # does not fail | ||
self.assertNotIn('test_regrtest_a', sys.modules) | ||
self.assertIs(sys.modules['test_regrtest_b'], test_regrtest_b) | ||
self.assertIs(sys.modules['test_regrtest_b.util'], test_regrtest_b.util) | ||
self.assertIn('test_regrtest_c', sys.modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Fixed order dependence in running tests in the same process | ||
when a test that has submodules (e.g. test_importlib) follows a test that | ||
imports its submodule (e.g. test_importlib.util) and precedes a test | ||
(e.g. test_unittest or test_compileall) that uses that submodule. |