[SciPy-Dev] Measuring test coverage of a Cython module

Lars G. lagru at mailbox.org
Fri Mar 30 11:50:15 EDT 2018


On 28.03.2018 06:06, Ralf Gommers wrote:
> On Mon, Mar 26, 2018 at 11:11 AM, Lars G. <lagru at mailbox.org
> <mailto:lagru at mailbox.org>> wrote:
> 
>     Hi,
>     I'm trying to measure the test coverage of a Cython module. However the
>     module in question (`scipy/signal/peak_finding_utils.pyx`) doesn't show
>     up in the final report.
> 
>     What I have tried so far:
> 
>     1. Added `plugins = Cython.coverage` to the `.coveragerc` file.
> 
>     2. Added
>     # cython: linetrace=True
>     # distutils: define_macros=CYTHON_TRACE_NOGIL=1
>     to the header of `peak_finding_utils.pyx`
> 
>     3. Build binaries inplace with
>     $ python setup.py build_ext --inplace
> 
>     4. Measured test coverage
>     a) with `runtests.py`
>     $ python runtests.py -t scipy/signal/tests/test_peak_finding --no-build
>     --coverage
> 
>     b) and using the `coverage` package
>     $ coverage run -m pytest scipy/signal/tests/test_peak_finding.py
>     $ coverage html
> 
> 
> The one step missing here seems to be editing .coveragerc:
> http://cython.readthedocs.io/en/latest/src/tutorial/profiling_tutorial.html?highlight=coverage#enabling-coverage-analysis

Actually I did that with step 1.

> The only discussion I remember is one on the scikit-image list started
> by Matthew Brett to get this working; not sure if that came to anything.
> In general it looks like it should work, but it isn't always reliable
> (e.g. https://github.com/cython/cython/issues/1985)

Thanks for the link and your time. I'll look into it and report back if
I figure it out.

Best regards, Lars



More information about the SciPy-Dev mailing list