Autodetect imports on pytest tests directory

I have a python project with the following (widespread) structure:

- src
- mypackage
- tests

I can run the tests from the terminal via

python -m pytest tests

However running the tests from the IDE (clicking on the green play button next to the test method) fails due to the `import mypackage` statement, as it cannot find it.

Doing some searching I found which suggests to put a file named `pytest.ini` at the root of the project. This fixes the problem and I can run the tests.

The problem I have not managed to fix is the import resolving / autodetection. On the IDE, the `import mypackage` still shows as unresolved. I could "fix" it by installing the package, but I would like to avoid installing the package before running the tests whenever I want to use the IDE to travel through function definitions and whatnot. Is there any way to do this?



Please sign in to leave a comment.