From 5883ae56b3e993052c46f7d9e756465b1387dd34 Mon Sep 17 00:00:00 2001 From: Filipa Andrade Date: Sat, 18 May 2013 17:04:52 +0200 Subject: [PATCH] Fixed #20142 -- Added error handling for fixture setup TestCase._fixture_setup disables transactions so, in case of an error, cleanup is needed to re-enable transactions, otherwise following TransactionTestCase would fail. --- django/test/testcases.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 6fe6b9c397c..6f8cbabd864 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -843,13 +843,17 @@ class TestCase(TransactionTestCase): for db in self._databases_names(include_mirrors=False): if hasattr(self, 'fixtures'): - call_command('loaddata', *self.fixtures, - **{ - 'verbosity': 0, - 'commit': False, - 'database': db, - 'skip_validation': True, - }) + try: + call_command('loaddata', *self.fixtures, + **{ + 'verbosity': 0, + 'commit': False, + 'database': db, + 'skip_validation': True, + }) + except Exception: + self._fixture_teardown() + raise def _fixture_teardown(self): if not connections_support_transactions():