Skip to content

Commit c8d9798

Browse files
committed
Try alternative way of parallelizing coverage
1 parent db903d4 commit c8d9798

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

hypothesis-python/.coveragerc

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[run]
2+
parallel = True
23
branch = True
4+
source = hypothesis
35
omit =
46
**/_hypothesis_ftz_detector.py
57
**/_hypothesis_pytestplugin.py

hypothesis-python/docs/strategies.rst

+20
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ loading our pytest plugin from your ``conftest.py`` instead::
212212
echo "pytest_plugins = ['hypothesis.extra.pytestplugin']\n" > tests/conftest.py
213213
pytest -p "no:hypothesispytest" ...
214214

215+
Another alternative, which we in fact use in our CI self-tests because it works
216+
well also with parallel tests, is to automatically start coverage early for all
217+
new processes if an environment variable is set.
218+
This automatic starting is set up by the PyPi package :pypi:`coverage_enable_subprocess`.
219+
220+
This means all configuration must be done in ``.coveragerc``, and not on the
221+
command line::
222+
223+
[run]
224+
parallel = True
225+
source = ...
226+
227+
Then, set the relevant environment variable and run normally::
228+
229+
python -m pip install coverage_enable_subprocess
230+
export COVERAGE_PROCESS_START=$PATH/.coveragerc
231+
pytest [-n auto] ...
232+
coverage combine
233+
coverage report
234+
215235

216236
.. _alternative-backends:
217237

hypothesis-python/tox.ini

+11-2
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,29 @@ allowlist_externals =
218218
setenv=
219219
PYTHONWARNDEFAULTENCODING=1
220220
HYPOTHESIS_INTERNAL_COVERAGE=true
221+
COVERAGE_PROCESS_START=.coveragerc
221222
commands_pre =
222223
rm -f branch-check*
223224
pip install .[zoneinfo]
225+
pip install coverage_enable_subprocess
226+
commands_post =
227+
pip uninstall -y coverage_enable_subprocess
224228
# Produce a coverage report even if the test suite fails.
225229
# (The tox task will still count as failed.)
226230
ignore_errors = true
231+
# We've had problems correctly measuring coverage using pytest-cov when running
232+
# in parallel, so instead we start coverage implicitly on all (sub-)processes by
233+
# way of the coverage_enable_subprocesses installation. This requires all options
234+
# to be set in .coveragerc (including source), but that's ok as it is overridden
235+
# by --cov=... in conjecture-coverage.
227236
commands =
228-
python -bb -X dev -m coverage run --rcfile=.coveragerc --source=hypothesis -m pytest -n0 --ff {posargs} \
237+
python -bb -X dev -m pytest -n auto --ff {posargs} \
229238
tests/cover tests/conjecture tests/datetime tests/numpy tests/pandas tests/lark \
230239
tests/redis tests/dpcontracts tests/codemods tests/typing_extensions tests/patching tests/test_annotated_types.py
240+
python -m coverage combine
231241
python -m coverage report
232242
python scripts/validate_branch_check.py
233243

234-
235244
[testenv:conjecture-coverage]
236245
deps =
237246
-r../requirements/coverage.txt

0 commit comments

Comments
 (0)