coverage misses with registed entrypoint
Hi,
I have encountered a strange problem with pytest-cov
I am writing a package to be included in other products. I want do provide some fixtures for mocking my package in the product tests.
At first I used pytest_plugin to include the fixtures in other product. Today i discovered automatic way to register the fixtures with pytest via the entrypoints in setup.py
Using the fixtures in the other products works well, but coverage test for the package itself fail.
Coverage reports any line normally covered by the import of the python file as miss. This includes import statements and the lines with function and class definitions. Any global code is also reported as not covered.
When I remove the entrypoint and reinstall the package. Everything is reported as covered.
What am I doing wrong?
My entrypoints look like this
entry_points={
'pytest11': [
'pyramid_mytum=pyramid_mytum.fixtures'
]
},
with the entrypoint active
---------- coverage: platform darwin, python 3.8.10-final-0 ----------
Name Stmts Miss Branch BrPart Cover Missing
------------------------------------------------------------------------------------------------------
src/pyramid_mytum/__init__.py 62 19 10 0 74% 1-21, 37, 66
src/pyramid_mytum/actions.py 126 24 52 0 87% 3-25, 71, 94, 121, 154, 210
in src/pyramid_mytum/init.py
lines 1-16 are import statements.
line 18 is a global definition
line 21, 37 and 66 are def statements
line 17, 19-20 are empty lines
without the entrypoints
---------- coverage: platform darwin, python 3.8.10-final-0 ----------
Name Stmts Miss Branch BrPart Cover Missing
------------------------------------------------------------------------------------------------------
src/pyramid_mytum/__init__.py 62 0 10 0 100%
src/pyramid_mytum/actions.py 126 0 52 0 100%
regards Estartu
It would appear that you need to do this: https://pytest-cov.readthedocs.io/en/latest/plugins.html
is there a way to fix this without the ENV variables. I have a .coveragerc and pytest.ini in my project.
Setting variables will be lost over time.
I'm attempting to do the same thing here. I've added the following to my tox.ini file, but I still get a failing coverage report. (My scenario: I forgot to add the entrypoint, and all my tests passed. Once I realized I needed the entrypoint, I removed the pytest_plugin reference and the tests all still pass, but the coverage completely ignores all lines.
[testenv]
usedevelop = True
setenv =
XUNIT_FILE=testresults-{envname}.xml
COV_CORE_SOURCE=my_module
COV_CORE_CONFIG={toxinidir}/.coveragerc
COV_CORE_DATAFILE=./coverage_results/.coverage-{envname}
COVERAGE_FILE=./coverage_results/.coverage-{envname}
commands =
rm -f .coverage
py.test --cov=my_module --cov-report term-missing --cov-report term:skip-covered
---------- coverage: platform linux, python 3.6.10-final-0 -----------
Name Stmts Miss Cover Missing
-------------------------------------------------------------------
mymodule/__init__.py 32 17 47% 3-20, 41, 52, 68, 79
mymodule/config.py 198 89 55% 1-47, 54, 58, 80, 97, 111-136, 145, 151, 156, 172, 184, 187, 192, 213, 228, 235, 252, 260-268, 280, 291, 301-302, 320, 339, 353, 369, 394, 399, 404, 416, 437, 445, 463, 475, 486, 489, 492, 499, 503-504, 511-512
mymodule/data_setup.py 20 17 15% 1-20, 23
mymodule/downstream.py 26 18 31% 1-41, 44, 48, 54, 62, 65
mymodule/exceptions.py 9 9 0% 1-51
mymodule/state_manager.py 93 33 65% 1-27, 37, 55, 63, 77, 93-94, 108, 119, 133, 156, 167, 174, 179, 199, 203, 211
-------------------------------------------------------------------
TOTAL 836 183 78%
8 files skipped due to complete coverage.