From 6824c9b7962a04ba03d846a8dbe2507d166672a6 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 31 Oct 2010 08:29:07 +0000 Subject: [PATCH] Ensure that assertNumQueries doesn't swallow exceptions inside the function. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14405 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/test/testcases.py | 5 ++++- tests/regressiontests/test_utils/tests.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 926fccdfda..4d06a59fa7 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -524,7 +524,10 @@ class TransactionTestCase(ut2.TestCase): context.__enter__() try: func(*args, **kwargs) - finally: + except: + context.__exit__(*sys.exc_info()) + raise + else: context.__exit__(*sys.exc_info()) def connections_support_transactions(): diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py index a8106ed6e6..995306e01d 100644 --- a/tests/regressiontests/test_utils/tests.py +++ b/tests/regressiontests/test_utils/tests.py @@ -8,6 +8,14 @@ if sys.version_info >= (2, 5): class SkippingTestCase(TestCase): + def test_assert_num_queries(self): + def test_func(): + raise ValueError + + self.assertRaises(ValueError, + self.assertNumQueries, 2, test_func + ) + def test_skip_unless_db_feature(self): "A test that might be skipped is actually called." # Total hack, but it works, just want an attribute that's always true.