IntelliJ 2019.2 Python Debug Unittests

Answered

After upgrading to 2019.2, I can no longer debug unit tests for my Python project. I can still run them, but debugging fails with ImportErrors on my own packages in my `tests` folder.

It looks like IntelliJ now has a folder called "tests" in `~/Library/Application Support/IntelliJIdea2019.2/python/helpers/pydev/tests`. This folder is injected into the python path when debugging tests, BEFORE my own source root. So, with 2019.2, that "tests" module is picked up before my own "tests" module.

I guess I can rename my own module to "test" for this project, but I really shouldn't have to. It's possible that I'm not understanding something here, but my first thought is that a common name like "tests" shouldn't have been used in this way by IntelliJ, such that it breaks any project that uses it. It took a bit of time this morning to troubleshoot this.

For reference, this is the output I get when debugging tests:

```

Testing started at 10:22 ...
/Users/dave/.local/share/virtualenvs/meetup-rsvps-server-vwWvvB9L/bin/python "/Users/dave/Library/Application Support/IntelliJIdea2019.2/python/helpers/pydev/pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 58168 --file "/Users/dave/Library/Application Support/IntelliJIdea2019.2/python/helpers/pycharm/_jb_unittest_runner.py" --target general_test.GeneralTest.test_get_server_status
pydev debugger: process 79839 is connecting

Error
Traceback (most recent call last):
File "/Users/dave/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 59, in testPartExecutor
yield
File "/Users/dave/.pyenv/versions/3.7.2/lib/python3.7/unittest/case.py", line 615, in run
testMethod()
File "/Users/dave/.pyenv/versions/3.7.2/lib/python3.7/unittest/loader.py", line 34, in testFailure
raise self._exception
ImportError: Failed to import test module: general_test
Traceback (most recent call last):
File "/Users/dave/.pyenv/versions/3.7.2/lib/python3.7/unittest/loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "/Users/dave/Projects/meetup_rsvps/meetup-rsvps-server/tests/general_test.py", line 34, in <module>
from tests.fixtures import copy
ModuleNotFoundError: No module named 'tests.fixtures'

```

0
1 comment

Hi,

You are right, there is a conflict with our tests folder from helpers.

The issue is known https://youtrack.jetbrains.com/issue/PY-37226, feel free to vote and leave comments.

0

Please sign in to leave a comment.