I have a weird scenario with pytest where we need to exclude the test directory from PYTHONPATH during the test.
Context
The pytest command for reference
python -m pytest main_project_a/folder_a/sub_project_a ...
I have main_project_a that requires to run test with a custom build of Python. It is built in the build folder. I need to use it to run the test in folder_a/sub_project_a. But modules in sub_project_a requires another package api_2, but pytest includes the test directory main_project_a/folder_a/sub_project_a in the PYTHONPATH, so it tried to look for api_2 in the test directory, which doesn't exist.
How to tell pytest no to include the test directory, or tell pytest to look in main_project_a/build/sub_project_a/lib/python3.9/sub_project_a instead?
WORKSPACE
- main_project_a
- ...
- build
- sub_project_a
- bin
- lib
- python3.9
- sub_project_a
- api
- api_2
- ...
- folder_a
- sub_project_a
- api
- module_a
- test
- module_b
- test