I am using Python 3.6.5 and testing with py.test.
I have had the following structure of my test folder.
tests/
some_folder/
test_module.py
utils.py
In test_module.py
I import utils.py
to use some functions from there. In test_module.py
I have a test function which runs perfectly when I execute it but when I try to debug it in PyCharm I receive
from tests import utils
ImportError: cannot import name 'utils'
So I tried to convert my tests folder into a package and it solved the problem. Now I have the following structure of my tests:
tests/
some_folder/
test_module.py
__init__.py
utils.py
But why it solves the problem? And why the problem does not occur when I simply run the test?