I have a Django app which has this structure:
app/
tests/
__init__.py
tests.py
__init__.py
test_model.py
In tests.py
I import the test model like: from app.test_model import *
. This works as expected: during testing, models are loaded, their corresponding database tables are created and so on.
But, if I move the test_model.py
file in the tests/
directory:
app/
tests/
__init__.py
test_model.py
tests.py
__init__.py
And do the import accordingly: from app.tests.test_model import *
, it suddenly fails. Models are not detected, hence their database tables are not created and tests start to fail (DatabaseError: no such table: app_model
).
Why is this happening? How should I avoid this and still place the test_model.py
file in tests/
?