[Django]-Django Package tests not found

6๐Ÿ‘

โœ…

You need to put from tests import * in your __init__.py file

Django will look in your app for a package/module called tests, and then interrogate its namespace for test cases. In this case it will look at the namespace of your tests package (from the init.py file), and discover nothing there. By doing the import in the __init__.py file then you will import the testcases from your tests module into the namespace of the tests package, and django will be able to locate them and run them.

2๐Ÿ‘

Another solution to this problem is to use more inteligent tests runner. You can try nose and django_nose โ€“ it will discover tests in this case. If you donโ€™t want to install aditional apps, @Ctrlspc solution is the only way to solve this problem.

0๐Ÿ‘

you can add a models.py file inside the app, add the new app to the installed apps and django will find the tests.py file without having to add anything to the __init__.py.

I guess both @Ctrlspc approach and this one are sort of dirty. so any choice is ok

Leave a comment