Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm, Django: zero code coverage

PyCharm has a "Run with Coverage" action for Django test targets. This runs the tests, but shows zero test coverage (0% files, not covered in the project pane, and all red in the editor). Checking or unchecking "Use bundled coverage.py" makes no difference.

Running the same tests from the CLI gives the expected results:

$ coverage --version
Coverage.py, version 3.5.1.  http://nedbatchelder.com/code/coverage


$ coverage run ./manage.py test blackbox
Creating test database for alias 'default'...
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Destroying test database for alias 'default'...


$ coverage report
Name                      Stmts   Miss  Cover
---------------------------------------------
__init__                      0      0   100%
blackbox/__init__             0      0   100%
blackbox/models               5      0   100%
blackbox/rules/__init__       1      0   100%
blackbox/rules/board         62     19    69%
blackbox/tests               49      6    88%
manage                       11      4    64%
settings                     24      0   100%
---------------------------------------------
TOTAL                       152     29    81%

What could cause this?

like image 592
abesto Avatar asked Mar 23 '12 14:03

abesto


People also ask

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.

How do I display code coverage?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.


1 Answers

If you access your project via any symlink in the path, coverage display will fail.

Try to open same project through real path, and you will get correct behavior.

https://youtrack.jetbrains.com/issue/PY-17616

PS: Refreshing old question, as bug still has not been fixed.

like image 166
Marek Avatar answered Sep 24 '22 17:09

Marek