pytest-cov icon indicating copy to clipboard operation
pytest-cov copied to clipboard

spurious files marked as uncovered _pytest/capture and pytest_cov/embed

Open graingert opened this issue 6 years ago • 12 comments

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

graingert avatar Aug 15 '19 14:08 graingert

Am I missing something here or why uncovered pytest internals are a problem?

ionelmc avatar Aug 15 '19 16:08 ionelmc

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%

graingert avatar Aug 15 '19 16:08 graingert

Note that the spurious files are in /opt/ not /src/

graingert avatar Aug 15 '19 16:08 graingert

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".

blueyed avatar Aug 15 '19 16:08 blueyed

Generally I expect --cov=/src/redacted to behave the same as .coveragerc [run]\n source=/src/redacted/

graingert avatar Aug 15 '19 16:08 graingert

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.

blueyed avatar Aug 15 '19 16:08 blueyed

..also I would try it without pytest-xdist to rule that out.

blueyed avatar Aug 15 '19 16:08 blueyed

I do pass cov-config explicitly

graingert avatar Aug 15 '19 16:08 graingert

..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

graingert avatar Aug 15 '19 17:08 graingert

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 avatar Aug 16 '19 09:08 graingert

@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.

blueyed avatar Aug 16 '19 15:08 blueyed

@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.

graingert avatar Aug 16 '19 15:08 graingert