question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature 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:open
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ionelmccommented, Jul 13, 2017

I’m trying this now, these changes seem to make it work.

Two things to consider:

  • setting the CYTHON_TRACE=1 macro ain’t enough, you also need to litter all your pyx files with # cython: linetrace=True pragmas.
  • you need to compile inplace (eg: 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).

0reactions
ionelmccommented, Jul 13, 2017

@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:

from os import environ
environ['CFLAGS'] = '-DCYTHON_TRACE=1'
import pyximport
pyximport.install()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cython: C-Extensions for Python
The Cython language is a superset of the Python language that additionally supports calling C functions and declaring C types on variables and...
Read more >
Cython support | PyCharm Documentation - JetBrains
PyCharm provides initial Cython support out of the box. PyCharm recognizes .pyx, .pxd, and .pxi files, and allows you to edit them.
Read more >
Basic Tutorial — Cython 3.0.0a11 documentation
Cython is Python: Almost any piece of Python code is also valid Cython code. ... The Pyximport module also has experimental compilation support...
Read more >
cython/cython: The most widely used Python to C compiler
The Cython language is very close to the Python language, but Cython additionally supports calling C functions and declaring C types on variables...
Read more >
Cython - PyPI
The Cython language is a superset of the Python language (almost all Python code is also valid Cython code), but Cython additionally supports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found