A replacement/wrapper around doctest to allow tests to be run in parallel
Project description
Parallel Doctest
Parallel Doctest splits doctests up and allows them to be
executed in parallel to help investigate concurrency bugs.
It is based on Python's standard-library doctest module.
Usage
Preparing tests
Parallel Doctest will first do a (crude) scan of your
doctest code to work out which individual tests within
a Doctest block depend on each other. For example
given a block::
>>> a = 1
>>> print(a)
1
>>> print(2)
The second line print(a) depends on the first line an thus should be run as a sequential series.
This is an automatic process although at this stage is fairly incomplete.
Tests can be marked as unsuitable for parallel execution with:
# doctest: +NO_PARALLEL_MODULEdisables parallel execution for the whole module.# doctest: +NO_PARALLEL_BLOCKdisables parallel execution for a given block (i.e. everything in a function docstring).# doctest: +NO_PARALLELdisables parallel execution for that example only (i.e. just a single line starting with>>>).
All these NO_PARALLEL directives disable parallelization for
the tests so that they will be the only test executing when they
are run.
Some control of serialization can be achieved with:
# doctest: +SEQUENTIAL_BLOCKmarks the whole block to be run in series. In this case the block may be run in parallel with other blocks but the individual tests in the block will be run in order.# doctest: +AFTER_PREVIOUSmanually adds a dependency for an individual doctest so that it is only run after the previous one (which must be in the same block).
Repeats
The number of repeats can be controlled with the option flags
PARALLEL_REPEAT_1, PARALLEL_REPEAT_2, PARALLEL_REPEAT_4,
going in factors of 2 up to PARALLEL_REPEAT_1024. These are
intended to be enabled at the command-line rather than set in
doctested code. To get (e.g.) 5 repeats use both PARALLEL_REPEAT_1
and PARALLEL_REPEAT_4. Parallel repeats only apply to parallel
tests and not to any test that's serialized.
Alternatively the environmental variable PARALLEL_DOCTEST_REPEAT
can be used to override it (and this takes priority).
High level interface
Parallel Doctest can be used from the command-line in the same way
as the Python doctest module::
python -m parallel_doctest -v example.py
Parallel Doctest also exposes the following high-level functions,
designed to match the Python doctest interface as much as possible::
testmod(m=None, ...) - pass a module object and test all
the docstrings of functions and classes in the module.
run_docstring_examples(f, ...) - pass a function, class, string, or module
and run all the doctests associated with that.
testfile(filename, ...) - load examples from a filename.
Unit test interface
Parallel Doctest doesn't expose the full unittest interface of doctest
directly, but instead has one function:
load_module_as_unittest_case(module) - loads all doctests from a module
into a single unittest.TestSuite.
Commentary
This tool was largely created to investigate thread-safety issues, both with thread sanitizer and Python level. It is intended for that rather than to try to speed up testing by parallelizing (which is probably more likely to be a pessimization, even on free-threaded builds of Python).
Most uses of doctest are for integration-level tests which may not
parallelize hugely well so be wary of that. SEQUENTIAL_BLOCK is
probably a good default option to apply globally as a reasonable
compromise between getting some parallelization and avoiding too many
failures due to side-effects.
A lot of doctests are based heavily round console output (it is what
it tests, after all!). parallel-doctest solves this by redirecting
sys.stdout and sys.stderr into thread-local variables.
This isn't expected to be hugely fast, so you may find your tests are
not doing too much parallel work. For best results, try to run tests that
do real work with a small amount of output.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parallel_doctest-0.0.1.tar.gz.
File metadata
- Download URL: parallel_doctest-0.0.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee84d36d2de56462bc902e3bc214098281a6b52f0931a4115e81e68ecb89b18b
|
|
| MD5 |
ab8b9643430092634124a7387d7c8964
|
|
| BLAKE2b-256 |
5e5af6cd4f35361c95eabe4c82264be0f32e4950c083207c52293c70decb306b
|
File details
Details for the file parallel_doctest-0.0.1-py3-none-any.whl.
File metadata
- Download URL: parallel_doctest-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d437be0e9b499ea5a484e6c1169995be95df780202e78639f27d9d576291a09
|
|
| MD5 |
97c9212a913d16b93c49a0ef24f75bef
|
|
| BLAKE2b-256 |
3661615100b4914c7bcea723a96ffab123a607b3d02d9fcbe84c11deca7ce636
|