pytest-cov
pytest-cov copied to clipboard
Getting test coverage when using testdir fixture on
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
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.
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