I have a python package for which I am trying to write unit tests The package looks as below
helper/
utils/
app/
requirements.txt
README.md
tests/
I come from java background so I thought of organizing the tests in the same package as that of their source therefore my tests directory looks as below
tests/
helper/
helper_a_test.py
utils/
util_a_test.py
app/
myapp_test.py
when I trying invoking the tests as below
python -m unittest discover
The test fails due to import error from source with error module app, helper, utils not found. I have __init__.py file is all my packages. I moved all the tests inside tests sub-directory into tests root directory as below.
tests/
helper_a_test.py
util_a_test.py
myapp_test.py
Now all test works as expected. Can someone explain why is this happening, also is it good practice to keep all tests inside one directory rather that on its own package?