Organizing cython source files and their tests (using nosetests)

When you play with nose and try to combine it with cython , I can’t get everything enough to work as I would like. The code is organized as follows:

. β”œβ”€β”€ setup.py └── src β”œβ”€β”€ calc β”‚  β”œβ”€β”€ factorial.py β”‚  β”œβ”€β”€ __init__.py β”‚  └── tests.py └── cycalc β”œβ”€β”€ tests.py └── triangle.pyx 

Each of tests.py contains 2 tests, one succeeds, one fails. The result of running setup.py nosetests is to execute only calc/tests.py . If after this run nosetests3 src/cycalc two tests are cycalc/tests.py in cycalc/tests.py . However, if I clear all the assembly files, this fails because cycalc/triangle.pyx not built into the shared lib.

Then I tried to add the src/cycalc/__init__.py , now setup.py nosetests selects cycalc/tests.py , but cannot find the necessary module, it is placed in src .

How do I configure cython source and tests so that setup.py nosetests finds everything it needs?

+6
source share
1 answer

For nose to run your tests automatically, you must add them to a folder called tests that contain all of your tests. Like this:

 . |-setup.py |-src |---calc |------factorial.py |------__init__.py |---cycalc |------triangle.pyx |------__init__.py |-tests |---__init__.py |---test_calc.py |---test_cycalc.py 

Thus, both tests will run automatically with the same path. If you delete the embedded files, you need to run python setup.py build before the tests work again.

+1
source

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


All Articles