Skip to content

Svenchi/numba_pytest_anotation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom anotations for testing numba

An issue with numba library that compiles Python code into machine code is that getting coverage results of test runs is impossible. Unitest currently does not return coverage of numba code. To alleviate this issue I created a custom annotation that detects if the code is run in test mode by checking if the "unittest" module is present, if it is, the numba code is compiled in python mode which gives us valid coverage.

Proof that it works

As a proof test directory contains two same python scripts located in numba_function_custom_anotation.py and numba_function_default_anotation.py that only differ in the annotations used. the default_annotation functions use default numba annotations, while custom annotations use previously explained custom logic. Two identical test suits have been setup in the test directory for these different functions.

Running tests locally produces the following coverage for the methods with differing annotations:

test/test_functions/numba_function_custom_anotation.py       23      2    91%
test/test_functions/numba_function_default_anotation.py      23     15    35%

As seen in these results, coverage is much more representative with the custom annotation.

executing proof:

to setup poetry environment run:

poetry install

generate coverage file:

poetry run coverage run -m pytest

get coverage details:

poetry run coverage report

After getting coverage details, the same result should appear as was shown before.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages