@@ -61,11 +61,30 @@ those fixtures are shared between threads.
6161
6262## Features
6363
64- - Three global CLI flags:
64+ - Global CLI flags:
6565 - ` --parallel-threads ` to run a test suite in parallel
6666 - ` --iterations ` to run multiple times in each thread
6767 - ` --skip-thread-unsafe ` to skip running tests marked as or
6868 detected to be thread-unsafe.
69+ - ` --mark-warnings-as-unsafe ` and ` --mark-ctypes-as-unsafe `
70+ to always skip running tests that use the ` warnings ` or
71+ ` ctypes ` modules, respectively. These are useful if you are
72+ adding support for Python 3.14 to a library that already
73+ runs tests under pytest-run-parallel on Python 3.13 or
74+ older.
75+ - ` --mark-hypothesis-as-unsafe ` , to always skip runing tests that
76+ use [ hypothesis] ( https://github.com/hypothesisworks/hypothesis ) .
77+ While newer version of Hypothesis are thread-safe, and versions
78+ which are not are automatically skipped by ` pytest-run-parallel ` ,
79+ this flag is an escape hatch in case you run into thread-safety
80+ problems caused by Hypothesis, or in tests that happen to use
81+ hypothesis and were skipped in older versions of pytest-run-parallel.
82+ - ` --ignore-gil-enabled ` , to ignore the RuntimeWarning generated
83+ when the GIL is enabled at runtime on the free-threaded build
84+ and run the tests despite the fact that the GIL is enabled.
85+ This option has no effect if pytest is configured to treat warnings
86+ as errors.
87+
6988
7089- Three corresponding markers:
7190 - ` pytest.mark.parallel_threads(n) ` to mark a single test to run
@@ -80,6 +99,8 @@ those fixtures are shared between threads.
8099 - ` num_parallel_threads ` : The number of threads the test will run in
81100 - ` num_iterations ` : The number of iterations the test will run in
82101 each thread
102+ - ` thread_index ` : An index for the test's current thread.
103+ - ` iteration_index ` : An index for the test's current iteration.
83104
84105** Note** : It's possible to specify ` --parallel-threads=auto ` or
85106` pytest.mark.parallel_threads("auto") ` which will let
@@ -125,18 +146,24 @@ current design with `@pytest.mark.thread_unsafe` or
125146` @pytest.mark.thread_unsafe(reason="...") ` .
126147
127148The following functions and modules are known to be thread-unsafe and
128- pytest-run-parallel will automatically not run tests using them in
149+ pytest-run-parallel will automatically skip running tests using them in
129150parallel:
130151
131- - ` pytest.warns `
132- - ` pytest.deprecated_call `
133152- The pytest ` capsys ` fixture
134153- The pytest ` monkeypath ` fixture
154+
155+ The following fixtures are known to be thread-unsafe on Python 3.13 and older,
156+ or on 3.14 and newer if Python isn't configured correctly:
157+
158+ - ` pytest.warns `
159+ - ` pytest.deprecated_call `
135160- The pytest ` recwarn ` fixture
136161- ` warnings.catch_warnings `
137162- ` unittest.mock `
138163- ` ctypes `
139- - Any test using [ hypothesis] ( https://hypothesis.readthedocs.io/en/latest/ ) .
164+
165+ If an older version of ` hypothesis ` that is known to be thread-unsafe is
166+ installed, tests using ` hypothesis ` are skipped.
140167
141168Additionally, if a set of fixtures is known to be thread unsafe, tests
142169that use them can be automatically marked as thread unsafe by declaring
@@ -237,6 +264,20 @@ Both modes of operations are supported simultaneously, i.e.,
237264$ pytest -x -v --parallel-threads=5 test_file.py
238265```
239266
267+ You can skip tests marked as or detected to be thread-unsafe by passing
268+ ` --skip-thread-unsafe ` in your pytest invocation. This is useful when running
269+ pytest-run-parallel under [ Thread
270+ Sanitizer] ( https://clang.llvm.org/docs/ThreadSanitizer.html ) . Setting
271+ ` --skip-thread-unsafe=True ` will avoid unnecessarily running tests where thread
272+ sanitizer cannot detect races because the test is not parallelized.
273+
274+ Older versions of pytest-run-parallel always marked tests using the ` warnings `
275+ and ` ctypes ` modules as thread-unsafe, since both were not thread-safe until
276+ Python 3.14. If you are adding support for Python 3.14 and would like to
277+ continue marking tests that use ` warnings ` or ` ctypes ` , pass
278+ ` --mark-warnings-as-unsafe ` or ` --mark-ctypes-as-unsafe ` , respectively, in your
279+ ` pytest ` invocation.
280+
240281Additionally, ` pytest-run-parallel ` exposes the ` num_parallel_threads `
241282and ` num_iterations ` fixtures which enable a test to be aware of the
242283number of threads that are being spawned and the number of iterations
@@ -252,12 +293,19 @@ def test_skip_if_parallel(num_parallel_threads):
252293 ...
253294```
254295
255- You can skip tests marked as or detected to be thread-unsafe by passing
256- ` --skip-thread-unsafe ` in your pytest invocation. This is useful when running
257- pytest-run-parallel under [ Thread
258- Sanitizer] ( https://clang.llvm.org/docs/ThreadSanitizer.html ) . Setting
259- ` --skip-thread-unsafe=True ` will avoid unnecessarily running tests where thread
260- sanitizer cannot detect races because the test is not parallelized.
296+ The ` thread_index ` and ` iteration_index ` fixtures are also avaliable, which enable
297+ tests to display different behavior between threads and iterations.
298+
299+ ``` python
300+ # test_file.py
301+ import numpy as np
302+
303+ def test_unique_rng_streams (thread_index ):
304+ # create an RNG stream with a seed that is deterministic
305+ # but still unique to this thread
306+ rng = np.random.default_rng(thread_index)
307+ ...
308+ ```
261309
262310Finally, the ` thread_comp ` fixture allows for parallel test debugging,
263311by providing an instance of ` ThreadComparator ` , whose ` __call__ ` method
0 commit comments