I have a directory structure that looks like this:
appdaemon
- apps
- shared
- __init__.py
- common.py
- __init__.py
- code.py
- tests
- __init__.py
- code_test.py
code.py
imports common.py
via:
from shared import common
This code runs just fine.
I'm trying to then run code_test.py
via pytest, which looks like:
from appdaemon_testing.pytest import automation_fixture
from apps.code import Code
...
This doesn't work, I get an error:
ImportError while importing test module '/config/appdaemon/tests/code_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/code_test.py:8: in <module>
from apps.code import Code
apps/code.py:3: in <module>
from shared import common
E ModuleNotFoundError: No module named 'shared'
How do I structure this so that the imports work within the test? Also, more generally, what am I missing in terms of my understanding of this import model?