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

Getting test coverage when using testdir fixture on

Open joshbadgervstg opened this issue 5 years ago • 2 comments

Summary

I am building out a testing framework, and as part of it I'm building fixtures on classes that inherit at various levels.

For example: a BaseTest class that all test classes inherit from, with a function-scoped fixture that creates artifacts on test failure. The easiest way to test these classes/fixtures work as expected is through creating tests using the testdir fixture (specifically, using testdir.makepyfile(), testdir.makeconftest(), and testdir.runpytest()) and running them, then validating that the artifacts were created (in this particular example).

However, the temporarily created and used file created by makepyfile does not seem to contribute to the coverage report, resulting in 0% coverage (despite importing from the actual file I hope to find coverage for). Is there something I need to add to my configuration to get this to work?

Expected vs actual result

Expected: Coverage report shows greater than 0% coverage on the BaseTest class file imported and used in testdir.makepyfile()-created file Actual: Coverage report shows 0% coverage on the BaseTest class file imported and used in testdir.makepyfile()-created file

Versions

pytest-cov 2.8.1

joshbadgervstg avatar Apr 15 '20 06:04 joshbadgervstg

I suspect the issue is coverage configuration (excessive or wrong filtering) but I can't put my finger on it until I see at least some kind of reproducer.

ionelmc avatar Apr 21 '20 09:04 ionelmc

Having the same issue, I figured out the coverage report is correct when using the testdir fixture, if and only if you run pytest with `--runpytest=subprocess

pytest --cov=. --cov-fail-under=100 --runpytest=subprocess

thomasleveil avatar Jun 04 '20 20:06 thomasleveil