[ Prev ] [ Index ] [ Next ]

ModuleNotFoundError

Created Samstag 20 März 2021


Description

You can get an ModuleNotFoundError: No module named 'module' error if you import parts of the Python package to test into the test module while running pytest.


Solution

(Src)
As you say yourself pytest basically assumes you have the PYTHONPATH setup up correctly. There are several ways of achieving this:



The reason for pytest to behave this way is to make it easy to run the tests in a tests/ directory of a checkout against an installed package. If it would unconditionally add the project directory to the PYTHONPATH then this would not be possible anymore.