I have an existing Python project which looks like this:
.venv/
...
example_package/
__init__.py
tests/
test_example_package.py
Imagine that I worked on this project for a while and then decided to add a frontend to some kind of web service using React.
I created a new directory called React
, and a new directory called Python
to organize my code.
The project structure now looks like this:
Python/
.venv/
...
example_package/
__init__.py
tests/
test_example_package.py
React/
...
But there is a problem. My tests no longer work. So I ran the VS Code “configure tests” command and set the subdirectory where the tests are to be found to Python
. But this did not fix the whole issue, and the pytest
discovery process fails with the following error:
ModuleNotFoundError: No module named 'example_package'
It seems relatively obvious as to what is happening. pytest
is being run by VS Code, with a current working directory set to .
instead of ./Python/
.
How can I fix this?