I have a python project, with a source tree like:
|-src
| |- module1
| | |- tests
| |- module2
| | |- tests
|- ...
It will be deployed to a docker as package mypkg
, in a way I cannot change -- transparently adding the mypkg
folder and __init__.py
.
Inside my code I generally import things with import mypkg.module1
or from mypkg.module2 import xyz
. However, since there is no mypkg
folder (and __init__.py
) under src
, pycharm does not recognize these imports and reports Unresolved reference
errors, and is not able to run pytest against any tests (even though they are not relying on any resource only available within the docker).
Right now for tests I change the imports in the tests from import mypkg.module1
to import module1
, run the tests in pycharm, fix bugs, change it back and commit. But as you can imagine this is error prone and annoying.
Is there any way I can tell pycharm or the python environment (maybe $PYTHONPATH
to recognize my package as mypkg
and act accordingly?
I'm using python 3.5+, exclusively (if that matters).