How to use coverage analysis using Cython

I am trying to run coverage analysis on some kind of Cython code using pytest-covcoveralls.io as well. I went on to create extension modules with tracing enabled and performed the analysis using the links below:

http://docs.cython.org/src/tutorial/profiling_tutorial.html

http://blog.behnel.de/posts/coverage-analysis-for-cython-modules.html

However, I get some results that I cannot explain. It seems that many of the lines of def/ cdef/ cpdefin the code show that they do not work, despite the fact that the code inside them is in order. The results are not even consistent, as some lines look normal.

Sample report: https://coveralls.io/files/1871744040

I do not know if I will call something wrong if this is a mistake, or if I simply do not correctly interpret the results.

coveralls screenshot

In the above example, the method get_costseems OK, but the method __set__for the above property is not called, even though the lines are inside the called function.

Update: it looks like the problem is with the Cython classes. If the class is defined using def, rather than cdef, the problem disappears. I assume that there is as yet no full support.

+4
source share
1 answer

Cython , gcov cython. , , - C .

main.pyx

import mymod

def main():
    mymod.test()

mymod.pyx

def test():
    return 42

cython --embed main.pyx
cython mymod.pyx

gcc -O1 -fPIC -fprofile-arcs -ftest-coverage -Wall -I/usr/include/python2.7 -c -o main.o main.c
gcc main.o -fprofile-arcs -lpython2.7 -lgcov -o main
gcc -O1 -fPIC -fprofile-arcs -ftest-coverage -Wall -I/usr/include/python2.7 -c -o mymod.o mymod.c
gcc -shared mymod.o -fprofile-arcs -lgcov -lpython2.7 -o mymod.so

. ./main main.gcda mymod.gcda gcov.

+1

Source: https://habr.com/ru/post/1625417/


All Articles