You need to add that directory to the path:
import sys
sys.path.append('../src')
Maybe put this into a module if you are using it a lot.
There are three ways to do what you want.
root_dir
├── my_module
│ ├── __init__.py
│ ├── main_file.py
│ ├── file1.py
│ ├── file2.py
└── tests
├── __init__.py
└── file1_test.py
All files in shoud import likemy_module
from my_module.file1 import some_function
Then you don't need to do any hacks
src and assuming statements likefrom src.file1 import some_function
are not what you want you need to modify your tests like
import os
import sys
sys.path.insert(0, os.path.abspath('src')
PYTHONPATH=path/to/src pytest
Is the virtual environment where you installed 'src' same, where you are trying this.
Pls. run the
pip list
in that virtual environment to check if 'src' is installed.
Also, pls. check the import statement in the python interpreter of your virtual env.