ashald / EnvFile

EnvFile 3.x is a plugin for JetBrains IDEs that allows you to set environment variables for your run configurations from one or multiple files.
MIT License
539 stars 129 forks source link

Cannot run pytest #88

Closed alessio-izzo closed 5 years ago

alessio-izzo commented 5 years ago

Hi, I recently had an issue running any test with pytest where the env variables where set by an .env file. This is the error message given by pycharm:

INTERNALERROR> self.ensure_test_start_reported(self.format_test_id(nodeid, location), test_name)
INTERNALERROR> File "/Applications/PyCharm CE.app/Contents/helpers/pycharm/teamcity/pytest_plugin.py", line 217, in ensure_test_start_reported
INTERNALERROR> self.teamcity.testStarted(test_id, flowId=test_id, captureStandardOutput=capture_standard_output, metainfo=metainfo)
INTERNALERROR> File "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_runner_tools.py", line 177, in testStarted
INTERNALERROR> commands = _TREE_MANAGER_HOLDER.manager.level_opened(self._test_to_list(testName), _write_start_message)
INTERNALERROR> File "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_runner_tools.py", line 50, in manager
INTERNALERROR> self._fill_manager()
INTERNALERROR> File "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_runner_tools.py", line 58, in _fill_manager
INTERNALERROR> from _jb_serial_tree_manager import SerialTreeManager
INTERNALERROR> ImportError: No module named _jb_serial_tree_manager

========================= no tests ran in 2.81 seconds =========================

Process finished with exit code 0

Empty suite

These are my settings: PyCharm 2019.1.3 (Community Edition) Build #PC-191.7479.30, built on May 29, 2019 JRE: 11.0.2+9-b159.60 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.14.5 The EnvFile version is 3.2.0 If I uncheck the use of the .env file, the tests run correctly.

ashald commented 5 years ago

I don't think it's related to the plugin - maybe some of the env vars you set break it?

alessio-izzo commented 5 years ago

Yes. I found out that the problem occurs when setting the PYTHONPATH variable. If I set PYTHONPATH into the file, the error is raised.

ashald commented 5 years ago

Glad you was able to figure it out! 😊

alessio-izzo commented 5 years ago

But there is a right way to set PYTHONPATH into the .env file? I mean, have you ever tried setting the pythonpath variable? If I set it in the usual way, I don't have problems.

ashald commented 5 years ago

You'd want to add a value to it rather than overwrite it altogether (as PyCharm manipulates it inject its helpers). For instance, if there is a dir src within your project that you want to add you can do it like this:

PYTHONPATH=src:${PYTHONPATH}

Also, don't forget to enable env var substitution as seen below:

image

P.S.: Please note that env var substitution is not a standard feature of env file format and is unlikely to work with anything else besides EnvFile plugin.