Pytest run configuration throws ModuleNotFoundError with docker remote interpreter

Context

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

 

Error

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

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

Process finished with exit code 4

Empty suite

 

Hypothesis

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.

 

0
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. 

0

Please sign in to leave a comment.