0

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
4
  • add test_ prefix to it Commented May 4, 2023 at 17:55
  • @Magaren, can you elaborate? Commented May 4, 2023 at 18:31
  • still need help? Commented May 5, 2023 at 15:41
  • hi @Magaren, i actually did not find a good solution for it after trying multiple scenarios and workaround, we ended up deciding to take the effort and rename the folder and update the references Commented Jun 1, 2023 at 1:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.