magic-removal: Improved model unit-test runner to rollback database for each test in case of exception

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2253 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-02-03 23:24:20 +00:00
parent e456bbb752
commit 23748415d3
1 changed files with 5 additions and 6 deletions

View File

@ -39,9 +39,13 @@ class DjangoDoctestRunner(doctest.DocTestRunner):
"Code: %r\nLine: %s\nExpected: %r\nGot: %r" % (example.source.strip(), example.lineno, example.want, got))
def report_unexpected_exception(self, out, test, example, exc_info):
from django.db import connection
tb = ''.join(traceback.format_exception(*exc_info)[1:])
log_error(test.name, "API test raised an exception",
"Code: %r\nLine: %s\nException: %s" % (example.source.strip(), example.lineno, tb))
# Rollback, in case of database errors. Otherwise they'd have
# side effects on other tests.
connection.rollback()
normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
@ -144,12 +148,7 @@ class TestRunner:
# has side effects on doctest TestRunner class.
runner = DjangoDoctestRunner(verbosity_level=verbosity_level, verbose=False)
self.output(1, "%s model: Running tests" % model_name)
try:
runner.run(dtest, clear_globs=True, out=sys.stdout.write)
finally:
# Rollback, in case of database errors. Otherwise they'd have
# side effects on other tests.
connection.rollback()
runner.run(dtest, clear_globs=True, out=sys.stdout.write)
if not self.which_tests:
# Run the non-model tests in the other tests dir