I started a project with what I would describe as a “standard” Python project structure, whereby my code is organized into a set of packages which all live in the top level directory. In addition to this, there is a tests
directory which contains .py
files with functions which define the test cases.
I would now like to segregate this from another new project which I will add to the same repository.
To do this, I propose to create two top level directories new_project
and old_project
under which everything will be organized. (Given the names, you could imagine this is part of some kind of migration.)
I don’t know how to make this work with pytest as it integrates with VS Code.
Here’s the proposed project structure, as a MWE:
new_project/
simple_package/
__init__.py
tests/
test_simple_package.py
old_project/
# copy & paste of the above
The files can contain minimal code to demonstrate the point.
$ cat new_project/simple_package/__init__.py
a = 1
$ cat new_project/tests/test_simple_package.py
from simple_package import a
def test_a():
assert a == 1
I see the following error message:
- In the
pytest
sidebar (left hand side): pytest Discovery Error [pytest-subdirectory-test] Show output to view error logs - In the output:
E ModuleNotFoundError: No module named 'simple_package'
Is it possible to configure pytest
to work with such a repository structure?
It would seem strange that this wouldn’t work, because many projects would likely be a mix of different code written in different programming languages. Therefore it would seem strange if the VS Code pytest
integration can only be made to work in the most simple case where all the Python packages are at the top level of the repository.