Fixed #25415 -- Made DiscoverRunner run system checks.
This commit is contained in:
parent
391c450fba
commit
5eff8a7783
|
@ -8,6 +8,7 @@ from django.test.utils import get_runner
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Discover and run tests in the specified modules or the current directory.'
|
help = 'Discover and run tests in the specified modules or the current directory.'
|
||||||
|
|
||||||
|
# DiscoverRunner runs the checks after databases are set up.
|
||||||
requires_system_checks = False
|
requires_system_checks = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -9,6 +9,7 @@ import unittest
|
||||||
import warnings
|
import warnings
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
||||||
|
from django.core.management import call_command
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
from django.test import SimpleTestCase, TestCase
|
from django.test import SimpleTestCase, TestCase
|
||||||
from django.test.utils import (
|
from django.test.utils import (
|
||||||
|
@ -555,6 +556,11 @@ class DiscoverRunner(object):
|
||||||
verbosity=self.verbosity,
|
verbosity=self.verbosity,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def run_checks(self):
|
||||||
|
# Checks are run after database creation since some checks require
|
||||||
|
# database access.
|
||||||
|
call_command('check', verbosity=self.verbosity)
|
||||||
|
|
||||||
def run_suite(self, suite, **kwargs):
|
def run_suite(self, suite, **kwargs):
|
||||||
kwargs = self.get_test_runner_kwargs()
|
kwargs = self.get_test_runner_kwargs()
|
||||||
runner = self.test_runner(**kwargs)
|
runner = self.test_runner(**kwargs)
|
||||||
|
@ -593,6 +599,7 @@ class DiscoverRunner(object):
|
||||||
self.setup_test_environment()
|
self.setup_test_environment()
|
||||||
suite = self.build_suite(test_labels, extra_tests)
|
suite = self.build_suite(test_labels, extra_tests)
|
||||||
old_config = self.setup_databases()
|
old_config = self.setup_databases()
|
||||||
|
self.run_checks()
|
||||||
result = self.run_suite(suite)
|
result = self.run_suite(suite)
|
||||||
self.teardown_databases(old_config)
|
self.teardown_databases(old_config)
|
||||||
self.teardown_test_environment()
|
self.teardown_test_environment()
|
||||||
|
|
|
@ -197,6 +197,7 @@ In the terminal, we can run our test::
|
||||||
and you'll see something like::
|
and you'll see something like::
|
||||||
|
|
||||||
Creating test database for alias 'default'...
|
Creating test database for alias 'default'...
|
||||||
|
System check identified no issues (0 silenced).
|
||||||
F
|
F
|
||||||
======================================================================
|
======================================================================
|
||||||
FAIL: test_was_published_recently_with_future_question (polls.tests.QuestionMethodTests)
|
FAIL: test_was_published_recently_with_future_question (polls.tests.QuestionMethodTests)
|
||||||
|
@ -250,6 +251,7 @@ past:
|
||||||
and run the test again::
|
and run the test again::
|
||||||
|
|
||||||
Creating test database for alias 'default'...
|
Creating test database for alias 'default'...
|
||||||
|
System check identified no issues (0 silenced).
|
||||||
.
|
.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Ran 1 test in 0.001s
|
Ran 1 test in 0.001s
|
||||||
|
|
|
@ -434,6 +434,10 @@ Tests
|
||||||
* Added support for :meth:`python:unittest.TestCase.subTest`’s when using the
|
* Added support for :meth:`python:unittest.TestCase.subTest`’s when using the
|
||||||
:option:`test --parallel` option.
|
:option:`test --parallel` option.
|
||||||
|
|
||||||
|
* ``DiscoverRunner`` now runs the system checks at the start of a test run.
|
||||||
|
Override the :meth:`.DiscoverRunner.run_checks` method if you want to disable
|
||||||
|
that.
|
||||||
|
|
||||||
URLs
|
URLs
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
|
|
|
@ -402,12 +402,18 @@ testing behavior. This behavior involves:
|
||||||
#. Running ``migrate`` to install models and initial data into the test
|
#. Running ``migrate`` to install models and initial data into the test
|
||||||
databases.
|
databases.
|
||||||
|
|
||||||
|
#. Running the :doc:`system checks </topics/checks>`.
|
||||||
|
|
||||||
#. Running the tests that were found.
|
#. Running the tests that were found.
|
||||||
|
|
||||||
#. Destroying the test databases.
|
#. Destroying the test databases.
|
||||||
|
|
||||||
#. Performing global post-test teardown.
|
#. Performing global post-test teardown.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.11
|
||||||
|
|
||||||
|
Running the system checks was added.
|
||||||
|
|
||||||
If you define your own test runner class and point :setting:`TEST_RUNNER` at
|
If you define your own test runner class and point :setting:`TEST_RUNNER` at
|
||||||
that class, Django will execute your test runner whenever you run
|
that class, Django will execute your test runner whenever you run
|
||||||
``./manage.py test``. In this way, it is possible to use any test framework
|
``./manage.py test``. In this way, it is possible to use any test framework
|
||||||
|
@ -566,6 +572,12 @@ Methods
|
||||||
Creates the test databases by calling
|
Creates the test databases by calling
|
||||||
:func:`~django.test.utils.setup_databases`.
|
:func:`~django.test.utils.setup_databases`.
|
||||||
|
|
||||||
|
.. method:: DiscoverRunner.run_checks()
|
||||||
|
|
||||||
|
.. versionadded:: 1.11
|
||||||
|
|
||||||
|
Runs the :doc:`system checks </topics/checks>`.
|
||||||
|
|
||||||
.. method:: DiscoverRunner.run_suite(suite, **kwargs)
|
.. method:: DiscoverRunner.run_suite(suite, **kwargs)
|
||||||
|
|
||||||
Runs the test suite.
|
Runs the test suite.
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.core.checks import register
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class SimpleModel(models.Model):
|
class SimpleModel(models.Model):
|
||||||
field = models.IntegerField()
|
field = models.IntegerField()
|
||||||
manager = models.manager.Manager()
|
manager = models.manager.Manager()
|
||||||
|
|
||||||
|
|
||||||
|
@register('tests')
|
||||||
|
def my_check(app_configs, **kwargs):
|
||||||
|
my_check.did_run = True
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
my_check.did_run = False
|
||||||
|
|
|
@ -17,7 +17,7 @@ from django.test.utils import (
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.six import StringIO
|
from django.utils.six import StringIO
|
||||||
|
|
||||||
from .models import SimpleModel
|
from .models import SimpleModel, my_check
|
||||||
|
|
||||||
|
|
||||||
class DummyObj(object):
|
class DummyObj(object):
|
||||||
|
@ -303,3 +303,8 @@ class CheckFrameworkReservedNamesTests(SimpleTestCase):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
self.assertEqual(errors, expected)
|
self.assertEqual(errors, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class ChecksRunDuringTests(SimpleTestCase):
|
||||||
|
def test_registered_check_did_run(self):
|
||||||
|
self.assertTrue(my_check.did_run)
|
||||||
|
|
Loading…
Reference in New Issue