Running tests on my project code installed with pip in developer mode (pip install -e .) does work by executing pytest from the command line. However, running the same tests within the same Python virtualenv using the Test Explorer UI of Visual Studio Code does not work, Python raises ModuleNotFoundErrors.
I confirmed that my package is installed by pip list -v, which prints:
myproject 0.0.0 /path/to/myproject
Furthermore, I wrote failing test to get the Python path during test execution:
import sys
def test_some_test():
print(sys.executable)
print(sys.path)
assert False
This confirms that the Python executable is the one from the virtualenv where my project code is installed. But the sys.path differs between the Test Explorer run and the command line run. The Test Explorer run does not include the /path/to/myproject in the sys.path, whereas the command line run does. Obviously, if the project's path is included in the sys.path, the package can be imported. Why is it missing from the Test Explorer UI run? How to make the Test Explorer use the packages installed in develop mode with pip?
I should add that the modules I try to import in my tests are in a package themselves, called mylib. So the actual import in my test is like
from mylib import function_under_test
def test_function_under_test():
...