Pytest run configuration throws ModuleNotFoundError with docker remote interpreter


I'm working on a python project with a Docker remote interpreter. I'm able to run pytests from the terminal, but unfortunately, the pytest run configurations fail with ModuleNotFoundError. 

Docker Desktop: 4.14.0 (91374)

Product Version: PyCharm 2022.2.3 (Professional Edition)

OS: macOS



/home/circleci/.pyenv/shims/python /opt/.pycharm_helpers/pycharm/ --target<name of my test>
Testing started at 11:32 ...
Launching pytest with arguments<name of my test> --no-header --no-summary -q in /home/circleci/project/src/<...>

ImportError while loading conftest '/home/circleci/project/src/<...>
E   ModuleNotFoundError: No module named 'pyspark'

Process finished with exit code 4

Empty suite



One problem I observe in the log is the remote path: the row "ImportError while loading conftest /home/circleci/project/src/<>" is correct, that's my remote path. However, it's followed by a 2nd line that is "/opt/project/src/<...>", this one is an old remote path that we don't use anymore and I didn't configure this in the current project, so I don't where PyCharm takes it.


1 comment

We managed to find a solution: for some reason, PyCharm overwrote some of the environment variables built into the image, e.g.,  PYTHONPATH. Once we added the same environment variable to the Run Configurations, then pytests started working again. 


Please sign in to leave a comment.