I have a project that has a model and other components each in a Cython library. I've created unittests and can run those fine with coverage but I only get coverage information for the test code itself (not the libraries the test code is calling). I've tried to use the debug trace operation in coverage but it doesn't show any attempt to read any of the library code (I get no entries for Tracing or Not tracing). I have linetrace, CYTHON_TRACE=1, and the .coveragerc item for the Cython.coverage plugin all turned on. I've tried to copy the model.c code up to \ but that didn't seem to help.
Here is the (partial) project structure:
\model.pyd
\setup.py
\src\models\windows\model.pyx
\src\models\windows\model.c
\src\models\submodel.pxi
\tests\models\test_model.py
The code in windows\model.pyx includes a number of platform independent pieces of code from \src\models like this:
include '..\\submodel.pxi'
setup.py is run from \ with
python setup.py build_ext --inplace
and looks like this:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Compiler.Options import directive_defaults
import numpy
# Needed for line_profiler - disable for production code
directive_defaults['linetrace'] = True
directive_defaults['binding'] = True
setup(
ext_modules = cythonize([
Extension("model",
["src\models\windows\model.pyx"]
#,extra_compile_args = ["-O3"]
# CYTHON_TRACE required for coverage and line_profiler. Remove for release.
,define_macros=[('CYTHON_TRACE', '1')]
)
] )
)
unittests is run from \tests\models with
coverage run -m unittest discover
Here is the coverage report output (with plugin debug enabled). test_model is running lots of code in model.pyx and submodel.pxi that's not reported here:
Loaded plugin 'Cython.Coverage': <Cython.Coverage.Plugin object at 0x02F2AA30>
Name Stmts Miss Cover
--------------------------------------------
test_model.py 40 1 98%
--------------------------------------------
TOTAL 40 1 98%
Each unit test starts with this code snippet to pull the pyd file from the higher directory:
sys.path.append('..\\..\\')
from model import Model
...
I'm sure this has something to do with the project structure and I don't mind copying source files into the test directories in order to load up the test harness but I can't quite figure out the correct combination to make that happen. All help is welcome.