coveragepy: pytest and multiprocessing: CoverageException: Can't combine line data with arc dat
Originally reported by Samuel Colvin (Bitbucket: samuelcolvin, GitHub: samuelcolvin)
I’m getting CoverageException: Can't combine line data with arc dat
when using coverage with the pytest-cov pytest extension. I think this is similar to #399, but that issue is closed.
Example failure on travis: https://travis-ci.org/samuelcolvin/arq/builds/148541711
The test causing problems is using click’s CliRunner
, code here. The CLI command that’s testing starts another process (using multiprocessing.Process
) to run the worker which is what’s causing the problem, if you prevent the worker process being started the exception doesn’t occur.
I tried changing the concurrency
mode but it made no difference.
To reproduce: clone, pip install -e . && pip install -r tests/requirements.txt
, py.test --cov=arq
.
relevant bits of pip freeze
:
click==6.6
coverage==4.2
pytest==2.9.2
pytest-cov==2.3.0
Let me know if you need anymore information.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 41 (25 by maintainers)
Commits related to this issue
- Add context on coverage config file bug. See: https://github.com/nedbat/coveragepy/issues/512#issuecomment-399707938 https://github.com/pytest-dev/pytest-cov/issues/168#issuecomment-327533847 http... — committed to kdeldycke/meta-package-manager by kdeldycke 4 years ago
- Specify coverage config in pytest-github service This change is a workaround for https://github.com/nedbat/coveragepy/issues/512. — committed to christoph-blessing/compenv by christoph-blessing 2 years ago
- Specifically pin pyproject.toml as pytest config source This is needed to fix the coverage failures detailed at https://github.com/nedbat/coveragepy/issues/512 We may instead need to have this liste... — committed to MetOffice/CSET by jfrost-mo 6 months ago
- Specifically pin pyproject.toml as pytest config source This is needed to fix the coverage failures detailed at https://github.com/nedbat/coveragepy/issues/512 We may instead need to have this liste... — committed to MetOffice/CSET by jfrost-mo 6 months ago
- Specifically pin pyproject.toml as pytest config source This is needed to fix the coverage failures detailed at https://github.com/nedbat/coveragepy/issues/512 We may instead need to have this liste... — committed to MetOffice/CSET by jfrost-mo 6 months ago
- AB#549 Explicitly specified --cov-config for pytest to workaround random errors https://github.com/nedbat/coveragepy/issues/512 — committed to DeiC-HPC/cotainr by Chroxvi 4 months ago
Original comment by Ionel Cristian Mărieș (Bitbucket: ionelmc, GitHub: ionelmc)
I’ve taken a look at this as well, my opinion is that a combination of configuration, subprocess use and cwd changes cause the problem. That’s why you get the data file saved without arcs (branch=False).
There are thee ways to deal with this:
--cov-config=setup.cfg
(pytest-cov will absolutize it beforetmpworkdir
is used). Alternatively, you could use a.coveragerc
(pytest-cov absolutize that if it exists).signal.kill(os.getpid(), signal.SIGTERM)
or even a thread.tmpworkdir
fixture).There is no bug in either coverage or pytest-cov here.
Also, note that
concurrency = multiprocessing
is completely un-necessary if you use pytest-cov (it completely manages coverage measurements in subprocesses for you).Yes, I use
branch = true
. As I understand it this changes the format of the file, as I mentioned above, so the results cannot be combined with runs that don’t include that. Something to do with multiprocess runs and thetoml
file not being included caused the mixed format issue for me.I’ve come to some different conclusions that Ionel did, though he was very helpful in getting me going with debugging with his aspectlib.
The problem here is the Process spawned by test_repeat_worker_close. It doesn’t find the same configuration file that the rest of the tests do. Specifying
--cov-config=setup.cfg
doesn’t help, because coverage.py only reads that file properly when it is read implicitly, not explicitly (that could be the subject of another bug report).I think this is a combination of the direct use of Process, which perhaps coverage.py hasn’t patched enough, and having settings in the implicitly-read setup.cfg file.
One simple solution is to move your coverage.py settings into a .coveragerc file. If you do that, things work.
Original comment by Ionel Cristian Mărieș (Bitbucket: ionelmc, GitHub: ionelmc)
Maybe you need to tell pytest-cov what is the coverage config file (eg
--cov-config=setup.cfg
).