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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With