Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage reporting for Numba JIT-compiled functions #32

Open
vc1492a opened this issue Jun 20, 2019 · 7 comments
Open

Add coverage reporting for Numba JIT-compiled functions #32

vc1492a opened this issue Jun 20, 2019 · 7 comments
Assignees
Labels
enhancement New feature of request packaging This issue relates in some way to packaging and testing

Comments

@vc1492a
Copy link
Owner

vc1492a commented Jun 20, 2019

Any functions with the @jit decorator are not read by pytest-cov as having been executed despite them running successfully within the unit tests, as they are compiled by numba as C and thus are not Python functions which are able to be evaluated by pytest-cov.

This occurs even when setting the environment variable to disable numba execution, e.g. NUMBA_DISABLE_JIT = "1".

@vc1492a vc1492a added the bug Something isn't working label Jun 20, 2019
@vc1492a vc1492a self-assigned this Jun 20, 2019
@vc1492a
Copy link
Owner Author

vc1492a commented Jun 28, 2019

Resolved by disabling Numba prior to pytest execution. Turns out while you can set environmental variables in a Python script, the updated values are only accessible from new processes. Although it's possible to spawn a new child process from within a Python script, this can become a little messy with the test and instead Numba is disabled in order to provide accurate coverage reporting.

I however believe the successful integration of unit tests with Numba would provide the appropriate set of tests for development, so I will be renaming this issue and reassigning its label. In development, unit tests should be executed successfully both with Numba enabled and disabled (only the coverage reporting is affected).

@vc1492a vc1492a changed the title Fix coverage reporting for Numba JIT-compiled functions Add coverage reporting for Numba JIT-compiled functions Jun 28, 2019
@vc1492a vc1492a added enhancement New feature of request and removed bug Something isn't working labels Jun 28, 2019
@vc1492a vc1492a added the packaging This issue relates in some way to packaging and testing label May 29, 2020
@newskooler
Copy link

Is there a plan to add support for this, such that pytest-cov can detect coverage with @jit functions too?
It would be really convenient.

P.S. If not, at least a good warning should exist, I guess.

@vc1492a
Copy link
Owner Author

vc1492a commented Jun 7, 2020

Thanks for asking @snenkov! At this time, I do not have a solution in mind to support coverage reporting of JIT-enabled functions within the code base. I read through the two issues referenced above (from other repositories), and it looks like a solution has yet to be found / developed. If you have any suggestions, please let me know!

I agree however that a warning during testing would at least be nice. We can include a warning as part of the next release.

@newskooler
Copy link

Thank for the reply @vc1492a .
May I ask, how do you handle such function in your unit tests?
Do you just test accepting that it will not reflect in coverage? Or do you let coverage ignore it? What's your approach?

I guess when removing the @njit decorator it still performs the function tests and it's reflected in the coverage, but that's a manual fix to the problem (not really a fix).

@vc1492a
Copy link
Owner Author

vc1492a commented Jun 7, 2020

See the unit tests within the repository, line 24 of tests/test_loop.py which contains a flag to enable or disable the use of numba in the unit tests. Numba is installed within the local testing environment (not within the continuous integration environment as reflected in requirements_ci.txt), and that line value set to True when desiring to test the code base with numba. This reduces the coverage reported from 99% to 94%, but still executes each unit test and provides an indication of pass / failure.

We're able to run tests with Numba enabled or disabled locally, but for Travis CI we simply run the testing suite with numba disabled (which also reflects how most users will use the PyNomaly software).

@s-weigand
Copy link

Did anyone try simply monkey patching the @jit decorator with a decorator which leaves the function unchanged for the unit test of that given function, and know if that works?

@samyhocine
Copy link

Hi, any news on that ? Would be really helpful to be able to do it without disabling numba :/

@vc1492a vc1492a added this to the Address Existing Bug Fixes milestone Aug 19, 2024
@vc1492a vc1492a removed this from the Address Existing Bug Fixes milestone Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature of request packaging This issue relates in some way to packaging and testing
Projects
None yet
Development

No branches or pull requests

5 participants