3

I am gathering the code coverage for my django app and looks like coverage.py doesn't collect the statistics if the module was imported relatively.

More detailed:

the directory structure looks like this:

project
    __init__.py
    apps
        __init__.py
        my_app
            __init__.py
            my_module.py
            tests.py

So if I do from .my_module import * in tests.py - then coverage.py won't gather the statistics for my_module.py. However, if I put from apps.my_app.my_module import *, the statistics is there.

I am using django-nose with coverage plugin and have --cover-package=apps.my_app flag while running tests.

Has anybody stumbled upon such? I don't really want to always have the full import path, unless I really have to, so any thoughts are appreciated.

iurii
  • 2,597
  • 22
  • 25

1 Answers1

0

I am not familiar with django-nose, but to resolve a similar problem without Django I installed pytest and pytest-cov packages and did something similar to:

py.test --cov app

which reported the coverage.

Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43