How to run tests without installing package?
I know this question has been already closed, but a simple way I often use is to call pytest
via python -m
, from the root (the parent of the package).
$ python -m pytest tests
This works because -m
option adds the current directory to the python path, and hence mypkg
is detected as a local package (not as the installed).
See: https://docs.pytest.org/en/latest/usage.html#calling-pytest-through-python-m-pytest
The normal approach for development is to use a virtualenv and use pip install -e .
in the virtualenv (this is almost equivalent to python setup.py develop
). Now your source directory is used as installed package on sys.path.
There are of course a bunch of other ways to get your package on sys.path for testing, see Ensuring py.test includes the application directory in sys.path for a question with a more complete answer for this exact same problem.