Guard regression data runner against multiprocessing re-entry (#9195)

Run discovery and result writing only from the script entrypoint. Spawn and forkserver imports as __mp_main__ must not recursively execute the complete test suite or remove the parent result file.

Assisted-by: OpenAI Codex: model version unavailable
This commit is contained in:
youknowdot authored and GitHub committed 2026-10-19 20:11:55 +09:00
1 parent 71eec23bee
commit c208352caf
1 file changed
+20 -15
+20 -15
View File
@@ -4,11 +4,6 @@ import unittest
from custom_text_test_runner import CustomTextTestRunner as Runner
from test.libregrtest.findtests import findtests
testnames = findtests()
# idk why this fixes the hanging, if it does
testnames.remove("test_importlib")
testnames.insert(0, "test_importlib")
def loadTestsOrSkip(loader, name):
try:
@@ -24,16 +19,26 @@ def loadTestsOrSkip(loader, name):
return loader.suiteClass((TestClass(name),))
loader = unittest.defaultTestLoader
suite = loader.suiteClass(
[loadTestsOrSkip(loader, "test." + name) for name in testnames]
)
def main():
testnames = findtests()
# idk why this fixes the hanging, if it does
testnames.remove("test_importlib")
testnames.insert(0, "test_importlib")
resultsfile = os.path.join(os.path.dirname(__file__), "cpython_tests_results.json")
if os.path.exists(resultsfile):
os.remove(resultsfile)
loader = unittest.defaultTestLoader
suite = loader.suiteClass(
[loadTestsOrSkip(loader, "test." + name) for name in testnames]
)
runner = Runner(results_file_path=resultsfile, verbosity=2)
runner.run(suite)
resultsfile = os.path.join(os.path.dirname(__file__), "cpython_tests_results.json")
if os.path.exists(resultsfile):
os.remove(resultsfile)
print("Done! results are available in", resultsfile)
runner = Runner(results_file_path=resultsfile, verbosity=2)
runner.run(suite)
print("Done! results are available in", resultsfile)
if __name__ == "__main__":
main()