Q: Absolute imports from "tests" package fails with ModuleNotFoundError in PyCharm debugger Given the following simple Python project,
$ tree
.
├── Pipfile
├── Pipfile.lock
├── src
└── tests
    ├── test_foo.py
    └── util.py

$ cat Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
ipython = "*"
pytest = "*"

[dev-packages]

[requires]
python_version = "3.9"

$ cat tests/util.py 
FOO = 5

$ cat tests/test_foo.py 
from tests.util import FOO


def test_foo():
    assert FOO == 5

Running the PyCharm debugger on test_foo using pytest with the appropriate pipenv --venv produces the following error:
Connected to pydev debugger (build 202.8194.15)
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tests.util'


A: In test_foo.py, if you print out the sys.path, you'll notice that PyCharm has injected <path_to_venv>/lib/python<version>/site-packages/IPython/extensions which happens to contain a tests module that clobbers the local namespace tests. This issue has already been reported upstream: see https://github.com/ipython/ipython/issues/11592.
There are two workarounds for now:

*

*Rename your tests directory to something else.

*Remove the <path_to_venv>/lib/python<version>/site-packages/IPython/extensions/tests folder.

