0%
October 20, 2021

How to Include Project Directory in sys.path when Running pytest

python

When performing unit tests we usually import modules in project-directory/src. For this to work, we have to make sure sys.path contains our project-directory when running pytest, so that

from src.utils.module_name import SomeClass

becomes possible. It is as simple as executing (instead of pytest -vv test/...)

python -m pytest -vv test/...

and make sure we have cded into project directory when running this script.