Cython coverage (nose).

138 views
Skip to first unread message

Romain Brault

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

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 setup.py nosetests


Where the tests are performed via nosetests

----------------------------------------------------------------------

Ran 20 tests in 0.092s


OK

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

setup.py                 10      0   100%   

---------------------------------------------------

TOTAL                    86     28    67%


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

[run]
plugins = Cython.Coverage
[report]
exclude_lines =
    pragma: no cover
    if __name__ == .__main__.:
omit =
    *test*
    */scipy/*
    */numpy/*
    */sklearn/*
    *stringsource*
    */Python/*
    */python/*
    */site-packages/nose/*
    *__init__*
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 setup.py. Do you know what I'm missing? Is there any way to cover function definition?
Reply all
Reply to author
Forward
0 new messages