3

Learning django as a part of it developing an app with TDD approach, after going through many internet pages I have chosen unittest for testing and coverage library to know the test covered. The problem is after executing the coverage run and generating the html report, it created a htmlcov folder in which I see it included the test coverage for all the django libraries too.. which is overwhelming for me to look into the folder and search for the test results of my app results.

I have installed the coverage as per the docs

$ pip install coverage

and executed this command $ coverage run manage.py test -v 2 then generated the html report $ coverage html which resulted in 423 items of html pages

How I can overcome this, I could see online tutorial using the pytest to generate nice reports but it is not possible when using unittest and coverage..

tried below options too..

2)

$ coverage run -m unittest discover && coverage report
$ coverage html

3)

$ coverage run manage.py unittest feed, users
$ coverage html

same result, how can I get the desired files which includes only my project and it's app files (models, views, forms etc.,)

ivardu
  • 179
  • 2
  • 15

1 Answers1

4

I got the answer to my problem, found answer reference from the stackoverflow and used it as reference as many other users has mentioned

[run] omit= /migrations/ which confused me, so tried the below command and it worked (,) should be used to separate multiple directories

$ coverage run --omit=*/venv/*,*/migrations/* manage.py test

Here is the result of my command:

$ coverage report -m
Name                Stmts   Miss  Cover   Missing
-------------------------------------------------
feed/__init__.py        0      0   100%
feed/admin.py           1      0   100%
feed/apps.py            3      0   100%
feed/models.py         10      2    80%   6-7
feed/tests.py          11      1    91%   18
feed/urls.py            3      0   100%
feed/views.py           6      2    67%   7-8
manage.py              12      2    83%   11-12
snet7/__init__.py       0      0   100%
snet7/settings.py      19      0   100%
snet7/urls.py           4      0   100%
users/__init__.py       0      0   100%
users/admin.py          1      0   100%
users/apps.py           3      0   100%
users/forms.py          7      0   100%
users/managers.py      20      1    95%   29
users/models.py        13      1    92%   19
users/tests.py         33      4    88%   19-20, 44-45
users/views.py          6      0   100%
-------------------------------------------------
TOTAL                 152     13    91%
ivardu
  • 179
  • 2
  • 15