I have been having a lot of trouble trying to run pytest. Basically the importing was not working properly. Let me explain. The folder structure of my project is the following:
src
└── api
├── __init__.py
├── app.py
├── document.py
└── tests
├── __init__.py
└── test_app.py
And app.py has the following import statement:
from document import Document
and obviously test_app.py
imports app
Whenever I runned pytest
from the src
folder it would throw the following error:
ModuleNotFoundError: No module named 'document'
But once I removed the __init__.py
file from the api
directory it just works out of the box.
src
└── api
├── __init__.py <--- REMOVED
├── app.py
├── document.py
└── tests
├── __init__.py
└── test_app.py
I have been reading many different threads, but none of them explains why this is so.
Anyone understands why?
Sources I have been reading through: