summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-08-09 23:51:55 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-08-09 23:51:55 +0000
commitfd579f24d79ac70f8339f1544f2c3707cf468800 (patch)
tree3788f9455897e6c884f404d34587130b2e633017 /tests
parent270234d1895d81698fda140caa43629ad77504e0 (diff)
Improved unit-test framework so that it handles database errors more elegantly
git-svn-id: http://code.djangoproject.com/svn/django/trunk@446 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runtests.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/runtests.py b/tests/runtests.py
index 2987b7db81..16c1951d28 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -111,8 +111,13 @@ 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)
- runner.run(dtest, clear_globs=True, out=sys.stdout.write)
-
+ 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.
+ db.rollback()
+
# Run the non-model tests in the other tests dir
self.output(1, "Running other tests")
other_tests_dir = os.path.join(os.path.dirname(__file__), OTHER_TESTS_DIR)
@@ -137,7 +142,7 @@ class TestRunner:
except Exception, e:
log_error(module, "Exception running tests", ''.join(traceback.format_exception(*sys.exc_info())[1:]))
continue
-
+
# Unless we're using SQLite, remove the test database to clean up after
# ourselves. Connect to the previous database (not the test database)
# to do so, because it's not allowed to delete a database while being