mirror of https://github.com/django/django.git
Fixed #12932 -- Added an extra argument to suite_result() in the test runner, and added **kwargs as protection against future changes. Thanks to Eric Holscher for the report and patch.
This is BACKWARDS INCOMPATIBLE for anyone that has written a custom DjangoTestRunner class since it was introduced in r12255. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12487 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a9b2ac25d1
commit
2fc19d8d6f
|
@ -232,16 +232,16 @@ def reorder_suite(suite, classes):
|
||||||
|
|
||||||
|
|
||||||
class DjangoTestSuiteRunner(object):
|
class DjangoTestSuiteRunner(object):
|
||||||
def __init__(self, verbosity=1, interactive=True, failfast=True):
|
def __init__(self, verbosity=1, interactive=True, failfast=True, **kwargs):
|
||||||
self.verbosity = verbosity
|
self.verbosity = verbosity
|
||||||
self.interactive = interactive
|
self.interactive = interactive
|
||||||
self.failfast = failfast
|
self.failfast = failfast
|
||||||
|
|
||||||
def setup_test_environment(self):
|
def setup_test_environment(self, **kwargs):
|
||||||
setup_test_environment()
|
setup_test_environment()
|
||||||
settings.DEBUG = False
|
settings.DEBUG = False
|
||||||
|
|
||||||
def build_suite(self, test_labels, extra_tests=None):
|
def build_suite(self, test_labels, extra_tests=None, **kwargs):
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
||||||
if test_labels:
|
if test_labels:
|
||||||
|
@ -261,7 +261,7 @@ class DjangoTestSuiteRunner(object):
|
||||||
|
|
||||||
return reorder_suite(suite, (TestCase,))
|
return reorder_suite(suite, (TestCase,))
|
||||||
|
|
||||||
def setup_databases(self):
|
def setup_databases(self, **kwargs):
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
old_names = []
|
old_names = []
|
||||||
mirrors = []
|
mirrors = []
|
||||||
|
@ -278,10 +278,10 @@ class DjangoTestSuiteRunner(object):
|
||||||
connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
|
connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
|
||||||
return old_names, mirrors
|
return old_names, mirrors
|
||||||
|
|
||||||
def run_suite(self, suite):
|
def run_suite(self, suite, **kwargs):
|
||||||
return DjangoTestRunner(verbosity=self.verbosity, failfast=self.failfast).run(suite)
|
return DjangoTestRunner(verbosity=self.verbosity, failfast=self.failfast).run(suite)
|
||||||
|
|
||||||
def teardown_databases(self, old_config):
|
def teardown_databases(self, old_config, **kwargs):
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
old_names, mirrors = old_config
|
old_names, mirrors = old_config
|
||||||
# Point all the mirrors back to the originals
|
# Point all the mirrors back to the originals
|
||||||
|
@ -291,13 +291,13 @@ class DjangoTestSuiteRunner(object):
|
||||||
for connection, old_name in old_names:
|
for connection, old_name in old_names:
|
||||||
connection.creation.destroy_test_db(old_name, self.verbosity)
|
connection.creation.destroy_test_db(old_name, self.verbosity)
|
||||||
|
|
||||||
def teardown_test_environment(self):
|
def teardown_test_environment(self, **kwargs):
|
||||||
teardown_test_environment()
|
teardown_test_environment()
|
||||||
|
|
||||||
def suite_result(self, result):
|
def suite_result(self, suite, result, **kwargs):
|
||||||
return len(result.failures) + len(result.errors)
|
return len(result.failures) + len(result.errors)
|
||||||
|
|
||||||
def run_tests(self, test_labels, extra_tests=None):
|
def run_tests(self, test_labels, extra_tests=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Run the unit tests for all the test labels in the provided list.
|
Run the unit tests for all the test labels in the provided list.
|
||||||
Labels must be of the form:
|
Labels must be of the form:
|
||||||
|
@ -322,7 +322,7 @@ class DjangoTestSuiteRunner(object):
|
||||||
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()
|
||||||
return self.suite_result(result)
|
return self.suite_result(suite, result)
|
||||||
|
|
||||||
def run_tests(test_labels, verbosity=1, interactive=True, failfast=False, extra_tests=None):
|
def run_tests(test_labels, verbosity=1, interactive=True, failfast=False, extra_tests=None):
|
||||||
import warnings
|
import warnings
|
||||||
|
|
|
@ -1371,7 +1371,7 @@ set up, execute and tear down the test suite.
|
||||||
write your own test runner, ensure accept and handle the ``**kwargs``
|
write your own test runner, ensure accept and handle the ``**kwargs``
|
||||||
parameter.
|
parameter.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.run_tests(test_labels, extra_tests=None)
|
.. method:: DjangoTestSuiteRunner.run_tests(test_labels, extra_tests=None, **kwargs)
|
||||||
|
|
||||||
Run the test suite.
|
Run the test suite.
|
||||||
|
|
||||||
|
@ -1392,11 +1392,11 @@ set up, execute and tear down the test suite.
|
||||||
|
|
||||||
This method should return the number of tests that failed.
|
This method should return the number of tests that failed.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.setup_test_environment()
|
.. method:: DjangoTestSuiteRunner.setup_test_environment(**kwargs)
|
||||||
|
|
||||||
Sets up the test environment ready for testing.
|
Sets up the test environment ready for testing.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.build_suite(test_labels, extra_tests=None)
|
.. method:: DjangoTestSuiteRunner.build_suite(test_labels, extra_tests=None, **kwargs)
|
||||||
|
|
||||||
Constructs a test suite that matches the test labels provided.
|
Constructs a test suite that matches the test labels provided.
|
||||||
|
|
||||||
|
@ -1417,7 +1417,7 @@ set up, execute and tear down the test suite.
|
||||||
|
|
||||||
Returns a ``TestSuite`` instance ready to be run.
|
Returns a ``TestSuite`` instance ready to be run.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.setup_databases()
|
.. method:: DjangoTestSuiteRunner.setup_databases(**kwargs)
|
||||||
|
|
||||||
Creates the test databases.
|
Creates the test databases.
|
||||||
|
|
||||||
|
@ -1425,13 +1425,13 @@ set up, execute and tear down the test suite.
|
||||||
that have been made. This data will be provided to the ``teardown_databases()``
|
that have been made. This data will be provided to the ``teardown_databases()``
|
||||||
function at the conclusion of testing.
|
function at the conclusion of testing.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.run_suite(suite)
|
.. method:: DjangoTestSuiteRunner.run_suite(suite, **kwargs)
|
||||||
|
|
||||||
Runs the test suite.
|
Runs the test suite.
|
||||||
|
|
||||||
Returns the result produced by the running the test suite.
|
Returns the result produced by the running the test suite.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.teardown_databases(old_config)
|
.. method:: DjangoTestSuiteRunner.teardown_databases(old_config, **kwargs)
|
||||||
|
|
||||||
Destroys the test databases, restoring pre-test conditions.
|
Destroys the test databases, restoring pre-test conditions.
|
||||||
|
|
||||||
|
@ -1439,13 +1439,14 @@ set up, execute and tear down the test suite.
|
||||||
database configuration that need to be reversed. It is the return
|
database configuration that need to be reversed. It is the return
|
||||||
value of the ``setup_databases()`` method.
|
value of the ``setup_databases()`` method.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.teardown_test_environment()
|
.. method:: DjangoTestSuiteRunner.teardown_test_environment(**kwargs)
|
||||||
|
|
||||||
Restores the pre-test environment.
|
Restores the pre-test environment.
|
||||||
|
|
||||||
.. method:: DjangoTestSuiteRunner.suite_result(result)
|
.. method:: DjangoTestSuiteRunner.suite_result(suite, result, **kwargs)
|
||||||
|
|
||||||
Computes and returns a return code based on a test suite result.
|
Computes and returns a return code based on a test suite, and the result
|
||||||
|
from that test suite.
|
||||||
|
|
||||||
|
|
||||||
Testing utilities
|
Testing utilities
|
||||||
|
|
Loading…
Reference in New Issue