Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organising cython source files and their tests (with nosetests)

When playing with nose and trying to combine it with cython I can't quite get it all to work the way I'd like. The code is organised like this:

.
├── setup.py
└── src
    ├── calc
    │   ├── factorial.py
    │   ├── __init__.py
    │   └── tests.py
    └── cycalc
        ├── tests.py
        └── triangle.pyx

Each of the tests.py contains 2 tests, one succeeds, one fails. The result of running setup.py nosetests is that only calc/tests.py are run. If I after this run nosetests3 src/cycalc the two tests in cycalc/tests.py are run. However, if I clean up all build files it fails because cycalc/triangle.pyx hasn't been built into a shared lib.

Then I tried adding the file src/cycalc/__init__.py, now setup.py nosetests picks up cycalc/tests.py but it fails to find the required module, it was placed in src.

How do I arrange my cython source and tests to make setup.py nosetests find everything it needs?

like image 985
Magnus Avatar asked Oct 05 '13 10:10

Magnus


1 Answers

For nose to run your tests automatically you should add them into a folder called tests containing all 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

This way both tests will be run automatically with everything in the same path. If you remove the built files you need to run python setup.py build before the tests will work again.

like image 140
while Avatar answered Sep 27 '22 22:09

while