I want my tests folder separate to my application code. My project structure is like so
myproject/
myproject/
myproject.py
moduleone.py
tests/
my
PYTHONPATH
env. varPYTHONPATH=. pytest
As mentioned by @J_H, you need to explicitly add the root directory of your project, since pytest
only adds to sys.path
directories where test files are (which is why @Mak2006's answer worked.)
If you are lazy and do not want to type that long command all the time, one option is to create a Makefile in your project's root dir with, e.g., the following:
.PHONY: install test
default: test
install:
pip install --upgrade .
test:
PYTHONPATH=. pytest
Which allows you to simply run:
make test
or (even shorter)
make
Another common alternative is to use some standard testing tool, such as tox.