I am having problems with pytest my directory looks like below:
├── modules
| ├── __init__.py
│ ├── data
| | ├── __init__.py
│ | └── tables.py
├── tests
│ └── test_tabels.py
└── main.py
My problem was that I was getting a Pytest Discovery Error
. When reading the error output I get ModuleNotFoundError: No module named modules
. In my test_tables.py
file I obviously need to import classes and definitions to test them, so I would for instance run from modules.data import GetData
.
By adding a __init__.py
file to the tests
folder I am not getting the error anymore and can run my tests. However, I do not understand why this works. I have other repos where I do not have an __init__.py
file in the tests
folder where I do not have the issue. This makes me wonder if I have actually solved the problem and if it makes sense to add the __init__.py
file.