Cannot run individual unit tests with Pytest - PyCharm in WSL

Setup:
Windows 10 Pro 1803 17134.706
WSL Ubuntu 18.04.2 LTS
PyCharm 2019.1.3 (Professional Edition)
Build #PY-191.7479.30, built on May 29, 2019
JRE: 11.0.2+9-b159.60 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Project:
Saleor release 2.7.0
Python 3.7.2
Pytest 4.6.2
Virtualenvwrapper
Virtualenv 16.6.0

Settings -> Languages & Frameworks -> Django - Do not use Django test runner is ticked
Settings -> Tools -> Python Integrated Tools -> Default test runner is set to pytest

What I am trying to achieve:
I am currently trying to debug individual unit tests with PyCharm by opening one of the test files, and clicking the debug or run button next to it.

What actually happens:
The debugger hits the first line of code, then stops. If I try to step through the code or wait a couple of seconds I then get the following output:

============================= test session starts ==============================
platform linux -- Python 3.7.2, pytest-4.6.2, py-1.8.0, pluggy-0.12.0
Django settings: tests.settings (from ini file)
rootdir: /mnt/c/Users/Peter/Documents/projects/project-name, inifile: setup.cfg
plugins: celery-4.3.0, cov-2.7.1, django-3.5.0, django-queries-1.0.0, forked-1.0.2, mock-1.10.4, vcr-1.0.2, xdist-1.28.0
gw0 I / gw1 I / gw2 I / gw3 I / gw4 I / gw5 I / gw6 I / gw7 I
gw0 [1] / gw1 [1] / gw2 [1] / gw3 [1] / gw4 [1] / gw5 [1] / gw6 [1] / gw7 [1]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/_pytest/main.py", line 206, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/_pytest/main.py", line 250, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/xdist/dsession.py", line 115, in pytest_runtestloop
INTERNALERROR> self.loop_once()
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/xdist/dsession.py", line 138, in loop_once
INTERNALERROR> call(**kwargs)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/xdist/dsession.py", line 249, in worker_testreport
INTERNALERROR> self.config.hook.pytest_runtest_logreport(report=rep)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/ubuntu/.virtualenvs/project-name/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/mnt/c/Users/Peter/AppData/Local/JetBrains/Toolbox/apps/PyCharm-P/ch-0/191.7479.30/helpers/pycharm/teamcity/pytest_plugin.py", line 324, in pytest_runtest_logreport
INTERNALERROR> self.teamcity.blockOpened(block_name, flowId=test_id)
INTERNALERROR> File "/mnt/c/Users/Peter/AppData/Local/JetBrains/Toolbox/apps/PyCharm-P/ch-0/191.7479.30/helpers/pycharm/teamcity/messages.py", line 92, in blockOpened
INTERNALERROR> self.message('blockOpened', name=name, flowId=flowId)
INTERNALERROR> File "/mnt/c/Users/Peter/AppData/Local/JetBrains/Toolbox/apps/PyCharm-P/ch-0/191.7479.30/helpers/pycharm/_jb_runner_tools.py", line 103, in message
INTERNALERROR> current, parent = _TREE_MANAGER_HOLDER.manager.get_node_ids(properties["name"])
INTERNALERROR> File "/mnt/c/Users/Peter/AppData/Local/JetBrains/Toolbox/apps/PyCharm-P/ch-0/191.7479.30/helpers/pycharm/_jb_parallel_tree_manager.py", line 69, in get_node_ids
INTERNALERROR> return self._branches[tuple(test_name.split("."))]
INTERNALERROR> KeyError: ('test setup',)

======================== no tests ran in 72.65 seconds =========================

Process finished with exit code 0

Any help anyone can provide is appreciated!

4 comments
Comment actions Permalink

I'm trying to do a similar setup to reproduce your case, but I'm running into some more serious issues if I try to run TestCase from django.test using pytest runner. I don't think this is expected to work, so I assume you're doing something different.

Can you reproduce the issue with a minimal code snippet and provide it here?

0
Comment actions Permalink

I'm having a similar issue. This is the last part of the error:
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

This happens only with a project and with others. 
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

0
Comment actions Permalink

@Alessio Izzo

Your issue seems to be identical to https://youtrack.jetbrains.com/issue/PY-36663 , but it's not the same as topic starter.

0
Comment actions Permalink

@peter_dermott

I'm suspecting a duplicate for this issue: https://youtrack.jetbrains.com/issue/PY-35423

Would you mind trying to reproduce the issue on 2018.3.6 (https://www.jetbrains.com/pycharm/download/previous.html) to confirm?

0

Please sign in to leave a comment.