summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2009-12-13 16:24:36 +0000
committerKaren Tracey <kmtracey@gmail.com>2009-12-13 16:24:36 +0000
commit92eec3ef9ae3eed18cef4cb7e87a85df4f06d3f0 (patch)
treeda7ec962435cf1c88397523dbdeb10233f2a5e7d /django/test
parentd10dd3eceb45b72746c974adaf7d9040aa48dd0a (diff)
Fixed #11613: Added a failfast option for test running. Thanks jukvalim and Randy Barlow.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11843 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test')
-rw-r--r--django/test/simple.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/django/test/simple.py b/django/test/simple.py
index f3c48bae33..c1f915b8cd 100644
--- a/django/test/simple.py
+++ b/django/test/simple.py
@@ -10,6 +10,26 @@ TEST_MODULE = 'tests'
doctestOutputChecker = OutputChecker()
+class DjangoTestRunner(unittest.TextTestRunner):
+
+ def __init__(self, verbosity=0, failfast=False, **kwargs):
+ super(DjangoTestRunner, self).__init__(verbosity=verbosity, **kwargs)
+ self.failfast = failfast
+
+ def _makeResult(self):
+ result = super(DjangoTestRunner, self)._makeResult()
+ failfast = self.failfast
+
+ def stoptest_override(func):
+ def stoptest(test):
+ if failfast and not result.wasSuccessful():
+ result.stop()
+ func(test)
+ return stoptest
+
+ setattr(result, 'stopTest', stoptest_override(result.stopTest))
+ return result
+
def get_tests(app_module):
try:
app_path = app_module.__name__.split('.')[:-1]
@@ -146,7 +166,7 @@ def reorder_suite(suite, classes):
bins[0].addTests(bins[i+1])
return bins[0]
-def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
+def run_tests(test_labels, verbosity=1, interactive=True, failfast=False, extra_tests=[]):
"""
Run the unit tests for all the test labels in the provided list.
Labels must be of the form:
@@ -189,7 +209,7 @@ def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
old_name = settings.DATABASE_NAME
from django.db import connection
connection.creation.create_test_db(verbosity, autoclobber=not interactive)
- result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
+ result = DjangoTestRunner(verbosity=verbosity, failfast=failfast).run(suite)
connection.creation.destroy_test_db(old_name, verbosity)
teardown_test_environment()