GeezerVison is showing github.com — test_sys.test_intern() fails if run more than once in the same process · Issue #108963 · python/cpython
test_sys.test_intern() fails if run more than once in the same process #108963DescriptionBug report
Example:
$ ./python -m test test_sys test_sys -m test_intern -v
(...)
0:00:00 load avg: 1.60 Run tests sequentially
0:00:00 load avg: 1.60 [1/2] test_sys
test_intern (test.test_sys.SysModuleTest.test_intern) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
0:00:00 load avg: 1.60 [2/2] test_sys
test_intern (test.test_sys.SysModuleTest.test_intern) ... FAIL
======================================================================
FAIL: test_intern (test.test_sys.SysModuleTest.test_intern)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vstinner/python/3.12/Lib/test/test_sys.py", line 687, in test_intern
self.assertTrue(sys.intern(s) is s)
AssertionError: False is not true
----------------------------------------------------------------------
(...)
Result: FAILURE
Linked PRs
Activityvstinner commented on Sep 6, 2023 @serhiy-storchaka: Oh, that another victim of regrtest trying to be nice :-) test_sys pass when run multiple times in the same process using this change:
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
index 16ae04191d..249e331434 100644
--- a/Lib/test/libregrtest/runtest.py
+++ b/Lib/test/libregrtest/runtest.py
@@ -436,7 +436,7 @@ def _load_run_test(result: TestResult, ns: Namespace) -> None:
module_name = abs_module_name(result.test_name, ns.testdir)
# Remove the module from sys.module to reload it if it was already imported
- sys.modules.pop(module_name, None)
+ #sys.modules.pop(module_name, None)
test_mod = importlib.import_module(module_name)
The interesting part is that ./python -m test -R 3:3 test_sys doesn't fail since it doesn't remove the test module between two test iterations ;-) serhiy-storchaka commented on Sep 6, 2023 For reference, the module level counter was added in aee3486 to prevent test_intern failing when it is rerun in verbose mode. But if the module is reloaded, the counter is reset.
One of solutions is to use the random module. Possibility of collisions in negligible.
Other solution -- use timer in the hope that the computer is not fast enough to finish the whole test several times in the time resolution unit.
We can also try to use id()s of some objects (self, globals(), locals()), but there is greater chance that all of them are allocated at exactly same address after reloading the module.
test_subinterp_intern_dynamically_allocated fails for the same reason.
aisk commented on Sep 16, 2023 Trying to change to using random.random() and it looks like it works well: #109491
C:\cpython>python -m test test_sys test_sys
Running Debug|x64 interpreter...
0:00:00 Run 2 tests sequentially
0:00:00 [1/2] test_sys
0:00:04 [2/2] test_sys
== Tests result: SUCCESS ==
All 2 tests OK.
Total duration: 8.9 sec
Total tests: run=148 skipped=12
Total test files: run=2/2
Result: SUCCESS
changed the title [-]sys.test_intern() fails if run more than once in the same process[/-] [+]test_sys.test_intern() fails if run more than once in the same process[/+] on Sep 18, 2023added a commit that references this issue on Oct 2, 2023gh-108963: using random to generate unique string in sys.intern test (#…
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|