pytest-cov
pytest-cov copied to clipboard
spurious files marked as uncovered _pytest/capture and pytest_cov/embed
when running with pytest --cov=/src/redacted/ -n auto
[run]
branch = True
concurrency =
multiprocessing
# pytest-twisted runs a twisted reactor in a greenlet
greenlet
pytest-4.5.0, py-1.8.0, pluggy-0.9.0
plugins: xdist-1.29.0, twisted-1.10, lazy-fixture-0.5.2, forked-1.0.2, cov-2.7.1
[2019-08-15T09:09:59.851Z] /opt/redacted/python/testingenv/lib/python2.7/site-packages/_pytest/capture.py 469 468 126 0 1% 5-730, 733-844
[2019-08-15T09:09:59.851Z] /opt/redacted/python/testingenv/lib/python2.7/site-packages/pytest_cov/embed.py 44 31 12 3 29% 16-22, 24-36, 52, 56, 69-97, 46->exit, 51->52, 55->56
I'm currently struggling to make a minimal reproducible example, if anyone has any advice I'd be grateful
I fixed it by passing source in the coveragerc:
[run]
source = /src/redacted/
branch = True
concurrency =
multiprocessing
# pytest-twisted runs a twisted reactor in a greenlet
greenlet
Am I missing something here or why uncovered pytest internals are a problem?
The problem is that they are listed as our source code, for example by moving the "source" config from addopts to .coveragerc our coverage percent grows from 76 to 79%
Note that the spurious files are in /opt/ not /src/
Is your problem that you are seeing files in the report that you are not interested in?
source is a good "workaround" then, and has other benefits (i.e. it will tell what files should be covered).
Other options would be using include or omit with "report".
Generally I expect --cov=/src/redacted to behave the same as .coveragerc [run]\n source=/src/redacted/
Yeah, I see.
That might indicate that a different config is used with some subprocess(es) maybe?
You could try COVERAGE_DEBUG=config to get more insights maybe. See https://github.com/nedbat/coveragepy/blob/c8643d84d6f2a89287ddce0e37cfca1eaf337d80/doc/cmd.rst#diagnostics
Try also --cov-config=.coveragerc to pass it in explicitly - IIRC there's some issue with autodetection.
..also I would try it without pytest-xdist to rule that out.
I do pass cov-config explicitly
..also I would try it without pytest-xdist to rule that out.
running a build without xdist. I highly suspect it's xdist causing the issue
ok I ran a build without xdist. With pytest --cov=/src/redacted/ and the config:
[run]
branch = True
concurrency =
multiprocessing
# pytest-twisted runs a twisted reactor in a greenlet
greenlet
@graingert Did it happen there then also? I still suggest making coverage.py dump debug information (to stderr or a file), and just check if it picks up your config everywhere.
@graingert Did it happen there then also?
Yes it did, I'm sorry I forgot to mention that!
I still suggest making coverage.py dump debug information (to stderr or a file), and just check if it picks up your config everywhere.