If you don't want to add the source path to each test file or change your PYTHONPATH
, you can use nose to run the tests.
Suppose your directory structure is like this:
project
package
__init__.py
module.py
tests
__init__.py
test_module.py
You should import the module normally in the test_module.py
(e.g. from package import module
). Then run the tests by running nosetests
in the project folder. You can also run specific tests by doing nosetests tests/test_module.py
.
The __init__.py
in the tests
directory is necessary if you want to run the tests from inside it.
You can install nose easily with easy_install
or pip
:
easy_install nose
or
pip install nose
nose extends unittest in a lot more ways, to learn more about it you can check their website: https://nose.readthedocs.org/en/latest/