Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Coverage.py ignore files with no coverage?

I first run

nosetests --with-coverage

So I should have a .coverage file with all the default settings.

Within folder_1, I have file_1.py, file_2.py, and file_3.py

When I cd into folder_1 and run

coverage report

It outputs:

enter image description here

It doesn't generate anything for file_3.py! But then when I run:

coverage report file_3.py

it says:

enter image description here

Does it skip files with no coverage in the report? How can I change it so the report shows me the results of every *.py file?

like image 833
Preethi Vaidyanathan Avatar asked Mar 28 '17 18:03

Preethi Vaidyanathan


People also ask

How does coverage work Python?

Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not. Coverage measurement is typically used to gauge the effectiveness of tests.

How do you exclude a function from code coverage in Python?

You can exclude them all at once without littering your code with exclusion pragmas. If the matched line introduces a block, the entire block is excluded from reporting. Matching a def line or decorator line will exclude an entire function.

What is Pragma no cover?

That exact # pragma: no cover is the hint that the part of code should be ignored by the tool -- see Excluding code from coverage .

What is coverage in Django coverage?

2019-04-30. Code coverage is a simple tool for checking which lines of your application code are run by your test suite. 100% coverage is a laudable goal, as it means every line is run at least once. Coverage.py is the Python tool for measuring code coverage.


1 Answers

You need to specify a source directory for coverage.py to find files that have never been executed at all. You can use --source=folder_1 on the command line, or [run] source=folder_1 in your .coveragerc file.

like image 150
Ned Batchelder Avatar answered Sep 19 '22 17:09

Ned Batchelder