0

My problem is that I'm using Django-nose with coverage but it shows the mentioned statements as non-executed, lowering my coverage percentages in a bad way. For some reason I have not discovered yet, my Django project loads functions and classes before coverage gets into action, as it is explained here:

Does coverage.py measure the function and class definitions?

I have tried the second solution, which is exactly what I am asking for, but got no result. I have fixed it temporarily with # pragma cover to get accurate percentages, but that is tedious, dirty and it is not obviously the way to do this.

Here you have the relevant details and settings of my project, related to this issue:

Django settings:

INSTALLED_APPS += ('django_nose', )
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
    '--with-coverage',
    '--cover-min-percentage=80',
    '--cover-package=home, main, study, administrate, examine',
    '--cover-inclusive',
    '--cover-erase',
    '--cover-html-dir=' + BASE_DIR + "/tests/.coverage_report",
    '--cover-html',
    '--verbosity=3',
    '--exe',
]

.coveragerc:

[run]
    omit =  *migrations*
            *admin.py*
            *urls.py*
            *__init__.py*

[report]
    exclude_lines =
        pragma: no cover
        import *

dev-requirements.txt:

Django==1.7.2
requests==2.6.0
coverage==3.7.1
django-debug-toolbar==1.3.2
django-nose==1.4.1
nose==1.3.7
sqlparse==0.1.16

I've been trying to fix this for hours and it's really frustrating! Thanks so much for any sort of advice.

Community
  • 1
  • 1
  • For anyone with the same problem, I finally solved it here: http://stackoverflow.com/questions/24668174/how-to-test-coverage-properly-with-django-nose?rq=1 Seems like 1.7 Django version changed the way of loading models and that breaks the plugin. – Carlos Ruiz Lantero Sep 01 '15 at 16:09

1 Answers1

0

As Carlos said,

Ditch nose args and run your coverage directly for accurate coverage

coverage run --branch --source=my_app1,my_app2 ./manage.py test
coverage report

and this will still use your .coveragerc file

[run]
omit =  *migrations*
        *admin.py*
        *urls.py*
        *__init__.py*
    .
    .
Community
  • 1
  • 1
Kashif Siddiqui
  • 1,476
  • 14
  • 26