Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Corrected the skipIfDBFeature and skipUnlessDBFeature decorators to a…

…ctually *run* the tests they decorate. Thanks to Alex for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14243 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 400125d718c6a005d81c7ed051a15687394c2743 1 parent cd63ce0
Russell Keith-Magee authored October 17, 2010
9  django/test/testcases.py
@@ -576,13 +576,16 @@ def _fixture_teardown(self):
576 576
             connection.close()
577 577
 
578 578
 def _deferredSkip(condition, reason):
579  
-    def decorator(test_item):
580  
-        if not (isinstance(test_item, type) and issubclass(test_item, TestCase)):
581  
-            @wraps(test_item)
  579
+    def decorator(test_func):
  580
+        if not (isinstance(test_func, type) and issubclass(test_func, TestCase)):
  581
+            @wraps(test_func)
582 582
             def skip_wrapper(*args, **kwargs):
583 583
                 if condition():
584 584
                     raise unittest.SkipTest(reason)
  585
+                return test_func(*args, **kwargs)
585 586
             test_item = skip_wrapper
  587
+        else:
  588
+            test_item = test_func
586 589
         test_item.__unittest_skip_why__ = reason
587 590
         return test_item
588 591
     return decorator
14  tests/regressiontests/test_utils/tests.py
... ...
@@ -1,9 +1,23 @@
1 1
 import sys
2 2
 
  3
+from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature
  4
+
  5
+
3 6
 if sys.version_info >= (2, 5):
4 7
     from python_25 import AssertNumQueriesTests
5 8
 
6 9
 
  10
+class SkippingTestCase(TestCase):
  11
+    def test_skip_unless_db_feature(self):
  12
+        "A test that might be skipped is actually called."
  13
+        # Total hack, but it works, just want an attribute that's always true.
  14
+        @skipUnlessDBFeature("__class__")
  15
+        def test_func():
  16
+            raise ValueError
  17
+
  18
+        self.assertRaises(ValueError, test_func)
  19
+
  20
+
7 21
 __test__ = {"API_TEST": r"""
8 22
 # Some checks of the doctest output normalizer.
9 23
 # Standard doctests do fairly

0 notes on commit 400125d

Please sign in to comment.
Something went wrong with that request. Please try again.