1. memedough
  2. pytest-cov
  3. Issues
Issue #10 new


Denis K.
created an issue

Im running my django tests with this plugin and it seems to me that starting at sessionstart is a way too late for coverage. is there any chance that it will get updated to start earlier (e.g. at configure) ?

Comments (4)

  1. andymccurdy

    I'm seeing similar problems in my project. I define some py.test fixtures in conftest.py. Any module imported at the top of conftest.py gets inaccurate coverage data. In my case, pytest-cov is reporting that all import statements and function declarations (def foo():) are missing coverage in the modules conftest.py imports.

  2. Daniele Sluijters

    Same issue, coverage is started too late causing classes and defines to show up as untested.

    As per coverage's FAQ:

    Q: Why do the bodies of functions (or classes) show as executed, but the def lines do not?

    This happens because coverage is started after the functions are defined. The definition lines are executed without coverage measurement, then coverage is started, then the function is called. This means the body is measured, but the definition of the function itself is not.

    To fix this, start coverage earlier. If you use the command line to run your program with coverage, then your entire program will be monitored. If you are using the API, you need to call coverage.start() before importing the modules that define your functions.

  3. Log in to comment