cannot report test coverage
I cannot successfully obtain a report of coverage for the Cython module dd.cudd. I have:
- followed the Cython instructions for enabling coverage analysis
- ensured that
coverage.pywith its C extension are installed, in order for theCython.Coverageplugin to work.
I am using nosetests---I do not know whether nose can cause additional difficulties.
Directory layout under /path roughly:
dd/
tests/
Normally, I run nosetests within tests/, because I want to ensure that nosetests will import dd from site-packages (I have also tried the -w option of nosetests).
I have tried running nosetests both inside the tests/ directory, and above it.
nose does not report any results for cudd.pyx.
When nose --with-coverage --cover-package=dd runs under tests/, it creates a .coverage that mentions both a /path/tests/dd/cudd.pyx file (nonexistent), as well as the existing /path/dd/dd/cudd.pyx. For the existing file, coverage report complains that
/path/dd/dd/cudd.pyx NotPython:
Couldn't parse '/path/dd/dd/cudd.pyx' as Python source: 'invalid syntax' at line 20
Also, manually editing the wrong path reported in .coveragerc produces again the above error.
These observations are with:
cython == 0.25.1nose == 1.3.7coverage == 4.2
How can I get coverage to be reported for Cython modules? It seems that this may be a problem both with paths that coverage.py reports, and with failure of coverage.py to parse Cython syntax. I am unsure whether this should be addressed by cython (e.g., in the coverage.py plugin Cython.Coverage), or by coverage.py, or both.
May have some relevance to #1461.
The problem likely relates to testing the package installed under site-packages, in contrast to:
and
@johnyf I'm not sure that's the reason. I'm having the same issue here. The error says coverage does find the pyx file, it simply fails parsing it. The error when failing to find a pyx file is different. @scoder
Actually, looking at Cython.Coverage, it does seem the generated C file (not the pyx file!) is used to find out about the original source code lines. I'm not sure why, since Cython injects __Pyx_TraceCall calls with (almost -- see issue #2264) the right information in the generated C code.
It looks like Cython.Coverage has a bug when it tries to match the src file location with the dir layout... https://github.com/cython/cython/issues/3636
I think that with https://github.com/cython/cython/pull/3831, this is probably fixed. Measuring coverage with a pip installed project is possible if the C-files are generated. Here https://github.com/aio-libs/yarl/blob/a3df0aa/.github/workflows/ci-cd.yml#L250 I wrapped cythonization of PYX files with a script that performs the conversion to C using the same set of options/directives as the PEP 517 build backend. This allowed me to build wheels separately and install them. The project is imported from site-packages/ but the testing is running via python -Im pytest in the project root which makes sure that the locally available package is not imported. But since the Cython.Coverage plugin requires C files, I additionally run the PYX-to-C conversion so that coveragepy can match the measured coverage with the PYX files and put that information into the report (it reports 0 lines and 100% coverage otherwise).
@scoder looks like this issue can be closed now.