7

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%   
5
  • Could you please update the question with your directory structure? Commented Feb 4, 2015 at 4:19
  • The output of the coverage report command would also be helpful. Commented Feb 4, 2015 at 4:28
  • sounds like it runs and shows packages test cases which you are using Commented Feb 4, 2015 at 4:32
  • 2
    Is it possible that you are missing __init__.py files in some of your modules? Commented Feb 4, 2015 at 4:43
  • Ohh yess!! Thank you @JessamynSmith :) It works!! Bad that i missed it.. Commented Feb 4, 2015 at 5:15

1 Answer 1

9

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.