Right now, if I want to run tests from all my apps, I go:
python manage.py test app1 app2 app3
If I run:
python manage.py test
The test of all apps in INSTALLED_APPS
are run, including the djan开发者_StackOverflow社区go ones. Is there a simple command to run the tests of all the apps that I have created?
Sadly there is no such command. Django has no way of telling which apps are "yours" versus which are someone else's.
What I would suggest is writing a new management command, call it mytest. Then create a new setting MY_INSTALLED_APPS. The mytest command will just run the test for every app in MY_INSTALLED_APPS. You'll want the mytest command to subclass django.core.management.base.AppCommand. django.core.management.call_command will also be helpful.
The only problem with this method is that you will have to constantly maintain the MY_INSTALLED_APPS setting to make sure it is correct.
You could create an management/commands/testmyapps.py for one of your app which has:
from django.core.management.base import BaseCommand, CommandError
import django.core.management.commands.test
from django.core import management
from django.conf import settings
class Command(django.core.management.commands.test.Command):
args = ''
help = 'Test all of MY_INSTALLED_APPS'
def handle(self, *args, **options):
super(Command, self).handle(*(settings.MY_INSTALLED_APPS + args), **options)
This works better in Django 1.6+: when you run python manage.py test,
only your tests will run (assuming you have the default settings for TEST_RUNNER)
Use nose django test runner, it takes care of this.
Reference: Django nose to run only project tests
精彩评论