[Django]-How do I run tests for all my Django apps only?

24👍

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.

2👍

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)

👤Nils

2👍

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)

0👍

Use nose django test runner, it takes care of this.

Reference:
Django nose to run only project tests

👤endre

Leave a comment