Measuring test coverage of a Cython module
![](https://secure.gravatar.com/avatar/5b5090abb749b7a84d70f08b1219f47d.jpg?s=120&d=mm&r=g)
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 This approach is based on this blog post: http://blog.behnel.de/posts/coverage-analysis-for-cython-modules.html In both cases a) and b) the PYX file sadly isn't included in the report and I don't know what to try next. Has anyone figured out a way to do this? If I've overlooked a related issue or conversation on the mailing list I apologize and would be grateful if you could point me to it. Best regards, Lars
![](https://secure.gravatar.com/avatar/5f88830d19f9c83e2ddfd913496c5025.jpg?s=120&d=mm&r=g)
On Mon, Mar 26, 2018 at 11:11 AM, Lars G. <lagru@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?...
This approach is based on this blog post: http://blog.behnel.de/posts/coverage-analysis-for-cython-modules.html
In both cases a) and b) the PYX file sadly isn't included in the report and I don't know what to try next. Has anyone figured out a way to do this? If I've overlooked a related issue or conversation on the mailing list I apologize and would be grateful if you could point me to it.
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) Ralf
![](https://secure.gravatar.com/avatar/5b5090abb749b7a84d70f08b1219f47d.jpg?s=120&d=mm&r=g)
On 28.03.2018 06:06, Ralf Gommers wrote:
On Mon, Mar 26, 2018 at 11:11 AM, Lars G. <lagru@mailbox.org <mailto:lagru@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?...
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
![](https://secure.gravatar.com/avatar/da3a0a1942fbdc5ee9a9b8115ac5dae7.jpg?s=120&d=mm&r=g)
Hi, pe, 2018-03-30 kello 17:50 +0200, Lars G. kirjoitti:
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.
I tried to do this for https://github.com/scipy/scipy/pull/8379 but without success (although don't remember any more what the issue was), so if you manage to figure it out that would be useful. Pauli
participants (3)
-
Lars G.
-
Pauli Virtanen
-
Ralf Gommers