Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Coverage for Django Project

I installed coverage.py to measure the code coverage for my Django project. (As mentioned here: https://docs.djangoproject.com/en/1.6/topics/testing/advanced/#integration-with-coverage-py)

But I currently have no test cases in my project. So, when I run coverage it says:

coverage run --source='.' manage.py test myapp
Creating test database for alias 'default'...

----------------------------------------------------------------------
Ran 0 tests in 0.000s

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

It clearly says that it ran 0 tests, but when I say

coverage report -m

It gives me a report with code coverage of 91%. Also it looks into only the models package that I have. It does not look into other packages that are there as part of my app.

So when I give

coverage run --source='.' manage.py test myapp/mypackage

It once again reports coverage only for models package.

How do I measure the code coverage for all packages of the app? Kindly help. Thanks in advance.

myproject/
├── myapp
│   ├── models
│   ├── services
│   ├── statis
│   ├── templates
│   ├── utils
│   └── views
└── myproject

Report:

Name                           Stmts   Miss  Cover   Missing
------------------------------------------------------------
manage                            11      2    82%   8-9
myapp/__init__                   0      0   100%   
myapp/admin                      1      1     0%   1
myapp/models/__init__            3      0   100%   
myapp/models/form/__init__      10      0   100%   
myapp/models/form/items         57      0   100%   
myapp/models/form/profile       14      0   100%   
myapp/models/form/sections      10      0   100%   
myapp/models/user/__init__      21      0   100%   
myapp/models/user/items         67      0   100%   
myapp/models/user/profile       13      1    92%   9
myapp/models/user/sections      60      0   100%   
myapp/tests                      1      0   100%   
myapp/urls                       7      7     0%   1-9
myproject/__init__                      0      0   100%   
myproject/manage                       11     11     0%   2-16
myproject/settings                     33      0   100%   
myproject/urls                          4      4     0%   1-6
myproject/wsgi                          4      4     0%   10-14
------------------------------------------------------------
TOTAL                            327     30    91%   
like image 667
Srikrishnan Suresh Avatar asked Mar 18 '23 04:03

Srikrishnan Suresh


1 Answers

When modules are missing from code coverage, a good first step is to check for any missing __init__.py files.

like image 157
Jessamyn Smith Avatar answered Mar 28 '23 01:03

Jessamyn Smith