Cython coverage (nose).

Skip to first unread message

Romain Brault

Oct 23, 2015, 7:57:35 AM10/23/15
to cython-users

I'm using coverage successfully with Python and Nosetests, however I can't manage to cover function's signature.

I'm using

Romain$ sudo coverage run nosetests

Where the tests are performed via nosetests


Ran 20 tests in 0.092s


dhcp233-150:Operalib-2 Romain$ coverage report

Name                  Stmts   Miss  Cover   Missing


operalib/Kernel.pyx      45     12    73%   10, 19, 32, 36, 40, 46, 49, 58, 68, 71, 75, 78

operalib/Model.pyx       31     16    48%   12, 20-27, 31, 35, 39, 43, 47, 51, 54-56                 10      0   100%   


TOTAL                    86     28    67%

theses missing lines corresponds (mostly) to function's signature in my .pyx files. My .coveragerc is

plugins = Cython.Coverage
exclude_lines =
    pragma: no cover
    if __name__ == .__main__.:
omit =
show_missing = True

Looking at the FAQ I found my problem:

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. 

But I can't  start coverage earlier than Do you know what I'm missing? Is there any way to cover function definition?
Reply all
Reply to author
0 new messages