Running pytest in PyCharm gives a ImportError: No module named teamcity.messages

When I run pytest in PyCharm I am getting the following traceback

Testing started at 2:36 PM ...
pytest /src/rheniser/pycharm/pycharm-community-2019.2.4/helpers/pycharm/
# Interpreter: python
# Pipeline: /src/rheniser/pycharm/pipelines/shader/2019-10-16.130908/shader.pipeline
# Test locations:
# /src/rheniser/git/bfd/dept/shader/tests/tests_unit
[python] Checking that interpreter exists ...
Python 2.7.13
[python] Running pytest [Timeout: 3600.0 sec] ...
============================= test session starts ==============================
platform linux2 -- Python 2.7.13, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: /src/rheniser, inifile:
collected 1 items / 1 errors

tests_shader/ .

generated xml file: /src/rheniser/git/bfd/dept/shader/tests/tests_unit/shader_bfd-dept-shader_linux_python_report.xml0
------------------------ timestamp: 2019-11-04 14:36:52 ------------------------
==================================== ERRORS ====================================
ERROR collecting pycharm/pycharm-community-2019.2.4/helpers/pycharm/
/src/rheniser/pycharm/pycharm-community-2019.2.4/helpers/pycharm/ in <module>
from teamcity import pytest_plugin
// in load_module
mod = imp.load_module(fullname, import_file, path, suffix)
/src/rheniser/pycharm/pycharm-community-2019.2.4/helpers/pycharm/teamcity/ in <module>
from teamcity.messages import TeamcityServiceMessages
E ImportError: No module named teamcity.messages
====================== 1 passed, 1 error in 0.32 seconds =======================
[python] Finished running pytest.

When I dump sys.path in I see that the path added by pycharm is /src/rheniser/pycharm/pycharm-community-2019.2.4/helpers. I think it is suppose to be /src/rheniser/pycharm/pycharm-community-2019.2.4/helpers/pycharm.

I am using the latest version as of this writing:

PyCharm 2019.2.4 (Community Edition)
Build #PC-192.7142.42, built on October 31, 2019
Runtime version: 11.0.4+10-b304.77 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 3.10.0-693.21.1.el7.x86_64
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Non-Bundled Plugins: IdeaVIM





Does it happen with all of your pytests?
How does it go if you configure a new project interpreter?



Thank you for your response. Yes, it happens with all of my pytests. Configuring a new project interpreter does now appear to help.

I suspect the issue to that PyCharm is appending the path


to the PYTHONPATH when is should be




Indeed, it should be ${INSTALL_LOCATION}/pycharm-community-2019.2.4/helpers/pycharm

That's odd that in your case it's different.

How did you install PyCharm and how do you run it?


I have the same issue. Is there a workaround? If so, what would it be. I can run pytest in the IDE console, but the integration with the IDE is broken (probably broke when I removed some stuff from my "Downloads" directory during backups).




Reinstalling pycharm from the JB toolbox fixed my issue :)


Please sign in to leave a comment.