Search code examples
pythondjangodjango-testing

Django run all tests at once


I am using Django==1.7c2 and I wan't to say to Django find and run all tests in my project. I just created a folder with __init__.py which is named tests instead of putting all in tests.py. Here is my file structure;

my_project/apps/my_app/
├── __init__.py
├── tests
    ├── __init__.py
    ├── my_first_test.py
    ├── my_second_test.py
├── ....
├── ....
└── ....

and my __init__.py in tests file is like;

from my_first_test import *
from my_second_test import *

I thought that Django would recognise my test folder initially, but when I run just this command;

python manage.py test

There is no test case that Django find to run.

$ python manage.py test
Creating test database for alias 'default'...

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
Destroying test database for alias 'default'...

I must run the tests for specific application in my project like;

python manage.py test my_project.apps.my_app.tests

It results;

----------------------------------------------------------------------
Ran 7 tests in 1.432s

OK
Destroying test database for alias 'default'...

I really don't like it, because I need to run all tests in all application in my project at once instead of running them one by one. I don't know what am I missing.

Is there a way to say Django find and run all test at once in all applications in the project?

Thank You!

#Edited

I have the apps in INSTALLED_APPS in my setting.py


Solution

  • Try this:

    $ ./manage.py test --pattern="*_test.py"
    

    Test discovery is based on the unittest module’s built-in test discovery. By default, this will discover tests in any file named “test*.py”.

    Note

    By the way you don't need import TestCases in __init__.py file if you are using standard test discovery (Django start using built-in test discovery since 1.6)