When I try to use Pytest and Streamlit in the same project, things go wrong in the module imports, and I'm not sure how to handle it.
My directory is as follows:
repo
├── main.py
├── app.py
├── utils
│ ├── __init__.py
│ ├── util_a.py
└── tests
├── __init__.py
└── test_a.py
The app.py
file includes the next import line:
import utils.util_a
...
Now, the streamlit application runs as expected with the following line:
streamlit run repo/app.py
But while I run py.test
I received an error message:
ModuleNotFoundError: No module named 'utils'
If I replace the import line in app.py
as follow:
import repo.utils.util_a
...
Surprisingly, Pytest runs as expected but the Streamlit application returns the next error:
ModuleNotFoundError: No module named 'repo'
What is the root cause of that error, and how can I deal with it? How can I use Pytest and Streamlit in the same project without causing an import conflict?
Thank you!