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

Why my method signature is not marked as covered?

Open ws1088 opened this issue 4 years ago • 3 comments

Hi, When I run code coverage with pytest --cov=xxx it shows that the lines inside my class method is covered but not the method signature line: image

Same for the class definition line and the import lines on the top of the file: image

Is there an option to turn this on? Thanks!

ws1088 avatar Feb 28 '21 20:02 ws1088

It appears that your code is imported before pytest-cov starts measuring coverage (eg: you have a custom pytest plugin that imports it or some other weird thing going on). I guess you could try to make a reproducer and we find a solution but you can also just run coverage run -m pytest instead (assuming you don't need pytest-cov's subprocess stuff).

See: https://pytest-cov.readthedocs.io/en/latest/plugins.html

ionelmc avatar Mar 05 '21 09:03 ionelmc

Hi, was this issue ever addressed? I am also experiencing the same with pytest cov and would rather use it over coverage because of the way I have things configured right now.

jaymedina avatar Jan 13 '22 04:01 jaymedina

This issue happens if a fixture is referenced as entry point https://docs.pytest.org/en/6.2.x/writing_plugins.html#setuptools-entry-points .

This happened to me in that case, which made me do a conditional in the setup.py (in case of testing) to fix this issue.


Only supposition but I assume that adding the fixture as entry point force the loading of the module before the coverage start. And as definition of function/classes happens only once, it is not considered as covered when the test run.

FreeYourSoul avatar Feb 01 '22 13:02 FreeYourSoul