Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Description
Feature or enhancement
This proposes adding an option to theregression test runner to run individual tests multiple times in parallel with the goal of uncovering multithreading bugs, especially in the free threading build.
Note that this is different from-j, --multiprocess
, which uses multiple processes to run different tests files in parallel. The motivation of-j
is to speed up the time it takes to run tests and the use of processes improves isolation. Here the goal is to detect thread-safety bugs (at the cost of extra time).
This is motivated by the experience of usinghttps://github.com/Quansight-Labs/pytest-run-parallel, which is a pytest plugin written by@lysnikolaou and@andfoy. We've used that effectively to find thread-safety bugs in C API extensions while working on free threading compatibility.
The proposed changes are limited to the Python-internaltest.regrtest
andtest.support
package and not the publicunittest
package.
New command line arguments
These are chosen to matchhttps://github.com/Quansight-Labs/pytest-run-parallel. I think using the same names across the Python ecosystem makes things a bit easier to remember if you work on multiple projects.
--parallel-threads=N [default=0]
, runs each test in N threads--iterations=N [default=1]
, number of times to run each test
Other support
Some of our test cases are not thread-safe (even with the GIL) because they modify global state or use non thread-safe unsafe modules (likewarnings
):
@support.thread_unsafe
- marks a test case as not safe to run in multiple threads. The test will be run once in the main thread (like normal) even when--parallel-threads=N
is specified.
Similar projects
There are a few existing projects that do essentially this for pytest and unittest, but they're not directly usable for Python's own test suite.
- https://github.com/Quansight-Labs/pytest-run-parallel
- https://github.com/tonybaloney/pytest-freethreaded
- https://github.com/amyreese/unittest-ft