Issues with Cython.Coverage

215 views
Skip to first unread message

Joshua Arnott

unread,
Jun 21, 2016, 12:22:04 PM6/21/16
to cython-users
Hello,

I'm attempting to use Coverage.py to provide coverage analysis for a Python package that consists mostly of Cython cdef classes. I've stumbled across some issues using the Cython.Coverage module. Not sure if I'm using it incorrectly or if there are some bugs.

I've set up an demonstration project here:

https://github.com/snorfalorpagus/hello_cython

If you run "test_hello.py" it should run coverage and produce the HTML output.

There are two issues:
  1. Coverage doesn't seem to detect `def/cdef/cpdef` statements within a `cdef class` - they are always marked as not run (red)
  2. The ignore statements in .coveragerc seem to be completely ignored for pyx files. This is seen in the example "meow" function in both hello.pyx (not ignored) and notcython.py (ignored correctly).

I would file a bug report but it seems trac.cython.org isn't working? I've very keen to get this working. I don't have any experience hacking on Cython but am willing to learn if someone can point me in the right direction.


Kind regards,


Josh

Stefan Behnel

unread,
Jun 25, 2016, 12:39:16 PM6/25/16
to cython...@googlegroups.com
Joshua Arnott schrieb am 21.06.2016 um 18:22:
> I'm attempting to use Coverage.py to provide coverage analysis for a Python
> package that consists mostly of Cython cdef classes. I've stumbled across
> some issues using the Cython.Coverage module. Not sure if I'm using it
> incorrectly or if there are some bugs.
>
> I've set up an demonstration project here:
>
> https://github.com/snorfalorpagus/hello_cython
>
> If you run "test_hello.py" it should run coverage and produce the HTML
> output.
>
> There are two issues:
>
> 1. Coverage doesn't seem to detect `def/cdef/cpdef` statements within a
> `cdef class` - they are always marked as not run (red)

It might help to set the directive "# cython: binding=True" at the top of
your pyx file.


> 2. The ignore statements in .coveragerc seem to be completely ignored
> for pyx files. This is seen in the example "meow" function in both
> hello.pyx (not ignored) and notcython.py (ignored correctly).

That's quite possible. Back then, I didn't care about ignoring things as
much as making things work at all. ;-)


> I would file a bug report but it seems trac.cython.org isn't working? I've
> very keen to get this working. I don't have any experience hacking on
> Cython but am willing to learn if someone can point me in the right
> direction.

The whole coverage integration plugin is in Cython/Coverage.py. Try
debugging the coverage package to see where things go wrong with the
ignored lines. My guess is that this happens somewhere in the reporting
step, i.e. after the runtime data collection.

Stefan

Joshua Arnott

unread,
Jun 27, 2016, 1:27:26 PM6/27/16
to cython-users, stef...@behnel.de
On Saturday, 25 June 2016 17:39:16 UTC+1, Stefan Behnel wrote:
Joshua Arnott schrieb am 21.06.2016 um 18:22:
> I'm attempting to use Coverage.py to provide coverage analysis for a Python
> package that consists mostly of Cython cdef classes. I've stumbled across
> some issues using the Cython.Coverage module. Not sure if I'm using it
> incorrectly or if there are some bugs.
>
> I've set up an demonstration project here:
>
> https://github.com/snorfalorpagus/hello_cython
>
> If you run "test_hello.py" it should run coverage and produce the HTML
> output.
>
> There are two issues:
>
>    1. Coverage doesn't seem to detect `def/cdef/cpdef` statements within a
>    `cdef class` - they are always marked as not run (red)

It might help to set the directive "# cython: binding=True" at the top of
your pyx file.

This doesn't seem to have any effect.
 

>    2. The ignore statements in .coveragerc seem to be completely ignored
>    for pyx files. This is seen in the example "meow" function in both
>    hello.pyx (not ignored) and notcython.py (ignored correctly).

That's quite possible. Back then, I didn't care about ignoring things as
much as making things work at all. ;-)


> I would file a bug report but it seems trac.cython.org isn't working? I've
> very keen to get this working. I don't have any experience hacking on
> Cython but am willing to learn if someone can point me in the right
> direction.

The whole coverage integration plugin is in Cython/Coverage.py. Try
debugging the coverage package to see where things go wrong with the
ignored lines. My guess is that this happens somewhere in the reporting
step, i.e. after the runtime data collection.

Stefan

I've had a look at the source code. I think I understand 70% of how it works (mapping lines from cython to C). I haven't been able to fix the more serious issue with cdef classes. The ignore issue should be easy to fix. Thanks for the help so far Stefan.

Josh
Reply all
Reply to author
Forward
0 new messages