Testing specific applications in Django

As far as I know, you can run tests for all installed applications or one application. Testing all applications seems to be redundant, as it usually contains native Django modules ( django.contrib.auth , etc.). Is it possible to create a test suite containing only those applications that I specify (to combine all tests with all applications in my project folder in my case)?

+4
source share
3 answers

You can write your own test runner that only checks your applications. in the past I used something like

tests/runner.py :

 from django.test.simple import DjangoTestSuiteRunner from django.conf import settings class AppsTestSuiteRunner(DjangoTestSuiteRunner): """ Override the default django 'test' command, include only apps that are part of this project (unless the apps are specified explicitly) """ def run_tests(self, test_labels, extra_tests=None, **kwargs): if not test_labels: PROJECT_PREFIX = 'my_project.' test_labels = [app.replace(PROJECT_PREFIX, '') for app in settings.INSTALLED_APPS if app.startswith(PROJECT_PREFIX)] return super(AppsTestSuiteRunner, self).run_tests( test_labels, extra_tests, **kwargs) 

you set this as your default test runner in settings.py

 TEST_RUNNER = 'my_project.tests.runner.AppsTestSuiteRunner' 
+5
source

It looks like you will need to run tests without the Django test runner.

https://docs.djangoproject.com/en/dev/topics/testing/#running-tests-outside-the-test-runner

+1
source

use nose and django nose

After setup, just run

./manage.py test

and he will check your applications.

+1
source

Source: https://habr.com/ru/post/1382035/


All Articles