You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_sys.test_intern() fails if run more than once in the same process #108963
@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 ;-)
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.
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, 2023
Activity
vstinner commentedon 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:
The interesting part is that
./python -m test -R 3:3 test_sysdoesn't fail since it doesn't remove the test module between two test iterations ;-)serhiy-storchaka commentedon 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_allocatedfails for the same reason.aisk commentedon Sep 16, 2023
Trying to change to using
random.random()and it looks like it works well: #109491[-]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[/+]gh-108963: using random to generate unique string in sys.intern test (#…
pythongh-108963: using random to generate unique string in sys.intern…
[3.12] gh-108963: using random to generate unique string in sys.inter…
pythongh-108963: using random to generate unique string in sys.intern…