cython: Coverage plugin broken with coverage.py 5.x

Coverage reporting using the Cython plugin does not work for the 5.x series of coverage.py. For example, attempting to run coverage tests on raysect produces errors:

python setup.py build_ext -j4 --inplace --line-profile
coverage run -m unittest discover

Output:

...................................................................................................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 435 tests in 2.122s

OK
Can't add file tracer data for unmeasured file '/home/jlovell/FUN/cherab/raysect/raysect/core/math/_vec3.pxd'

Attempting to produce HTML output also results in an error:

coverage html

Output:

Couldn't parse '/home/jlovell/FUN/cherab/raysect/raysect/core/acceleration/accelerator.pyx' as Python source: 'invalid syntax' at line 32

Using coverage.py 4.5 on the same set of build files results in no errors reported about pyx files, and the HTML output is produced successfully.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (14 by maintainers)

Commits related to this issue

Most upvoted comments

OK, I took some time to look into this issue from the Cython point of view by getting into Cython.Coverage and think that I got a pretty good feeling about what this plugin does/should do. I started to debug a little further and thats what I found out so far, maybe it will help someone else to track the problem down later. Let’s consider this a progress report on my findings up to this point.

As far as my debugging goes, the file_tracer method of Cython.Coverage.Plugin never returns an actual file tracer object to coverage.py right now, at least not in my specific constellation. Furthermore, it only gets called with .py files from site packages like pytest and such, but never with a single file from the package that I told it to actually measure. I literally don’t know where coverage gets the idea of a .pxd file from, because Cython.Coverage doesn’t seem to get in contact with any of these, or I didn’t find the function yet where this is supposed to happen. I’ll probably see if I can further debug something from the coverage side of things, but the situation as it stands right now leaves me rather clueless. Coverage.py however thinks that .pxd files are associated to Cython.Coverage.Plugin, so that seems to be fine so far.

Can this issue be closed now? coverage 7.1.0 works without this error.

Debugging is really what is needed here. At some point, either coverage or the plugin in Cython.Coverage take a wrong decision about the file, the function, or the coverage data. Once that point is found, there’s probably a way to fix it.

I can report this issue remains with Cython 3.0a7 and coverage 5.5.

Update: adding the inline function in offsets.pxd just pushed the problem into another declaration-only .pxd file

@webknjaz since neither of the projects linked to above use src/ layout, I’d think not. That issue though and your PR are something I’m sure I’ll run up against in other projects so I’ll have to keep an eye on it, so thank you for pointing it out