[TIP] Best practices for testing C extensions?
Daniel Knüttel
daniel.knuettel at daknuett.eu
Sun Sep 8 06:58:50 PDT 2019
Hi folks,
I have to write tests for a package that includes both python3 code and
C extensions (including numpy ufuncs). Usually I have a project
structure like this:
Package_Name/
package_name/
__init__.py
...
test/
test_some_stuff.py
...
setup.py
Dockerfile # This is for CI
so I basically run `python3 -m pytest test/` from `Package_Name` to run
my tests before pushing to CI.
Now I have some c extensions:
Package_Name/
package_name/
__init__.py
some_py_module.py
some_c_ext.c
...
test/
test_some_stuff.py
setup.py
Dockerfile
Now this does not work anymore because the local package overwrites
the one installed in my virtualenv after running `python3 setup.py
build install`.
I bypassed the problem by putting `test/` into another directory (now
it is `test/test/`) and writing a Makefile that runs
`((cd test && python3 -m pytest test/ -vv))`. But that doesn't seem to
be too elegant and I would like to keep the standard layout.
Also are there some other best practices to follow when testing
packages including C extensions?
Thanks in advance,
--
Daniel Knüttel <daniel.knuettel at daknuett.eu>
More information about the testing-in-python
mailing list