Cython support
See original GitHub issueFeature Request:
I’m working on a Python3.5 project which uses Cython v0.23.4 for several modules via the pyximport method. We’re using pytest 3.1.3 and pytest-cov 2.5.1. Currently pytest-cov only reports on .py files. Our tests are written with the convention of test_.py and within those, calls to “def” functions and methods within *.pyx files are made in order to test the output (inside of our *.pyx modules we have a “def” signature for every “cdef” implementation so that non-cython modules in our application can easily call cythonized code in pure python).
Example:
cdef int _return_pos_int():
return 1
def return_pos_int():
return _return_pos_int()
If we were testing the example above, our tests would call the function with the “def return_pos_int()” signature.
The current pytest-cov output ignores covered .pyx files, even if there are .py tests accessing those modules. Ideally, pytest-cov would be able to determine the coverage for cython .pyx modules as it does with normal .py modules.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I’m trying this now, these changes seem to make it work.
Two things to consider:
CYTHON_TRACE=1
macro ain’t enough, you also need to litter all your pyx files with# cython: linetrace=True
pragmas.python setup.py clean --all build_ext --force --inplace
if your using the cython support in setuptools)@darthlukan Your coverage report looks weird. Why do you have a bare
__init__.py
there? Where are the .so files being built/installed?Also, try removing source filters (just use a bare
--cov
till you see hits on pyx files).@darthlukan where are the .so files located then? if in the same place as the .pyx files then probably you’re only missing the macro definitions, eg: