Python coverage report covering only test file

Viewed 2737

I’m pretty new to contributing to open source projects and am trying to get some coverage reports so I can find out what needs more / better testing. However, I am having trouble getting the full coverage of a test. This is for pytorch

For example, lets say I want to get the coverage report of test_indexing_py.

I run the command:

pytest test_indexing.py --cov=../ --cov-report=html

Resulting in this:

================================================= test session starts =================================================
platform win32 -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: C:\Projects\pytorch
plugins: hypothesis-5.4.1, arraydiff-0.3, cov-2.8.1, doctestplus-0.4.0, openfiles-0.4.0, remotedata-0.3.2
collected 62 items

test_indexing.py ............................s.................................                                  [100%]

----------- coverage: platform win32, python 3.7.4-final-0 -----------
Coverage HTML written to dir htmlcov


=========================================== 61 passed, 1 skipped in 50.43s ============================================

Ok, looks like the tests ran. Now when I check the html coverage report, I only get the coverage for the test file and not for the classes tested (the tests are ordered by coverage percentage).

As you can see, I am getting coverage for only test_indexing.py. How do I get the full coverage report including the classes tested?

Any guidance will be greatly appreciated.

1 Answers

I think its because you are asking to check the coverage from the test running directory, ie where test_indexing.py is.

A better approach would be like running the test from the root directory itself, rather than test directory, it has several advantages like the configuration file reading and all.

And regarding your question, try running the test from the root directory and try

  • pytest path/to/test/ --cov --cov-report=html
Related