diff --git a/django/test/testcases.py b/django/test/testcases.py
index d044236..6f3f1c0 100644
a
|
b
|
class TestCase(TransactionTestCase):
|
879 | 879 | self.atomics[db_name].__exit__(None, None, None) |
880 | 880 | |
881 | 881 | |
| 882 | class CheckCondition(object): |
| 883 | """Descriptor class for deferred condition checking""" |
| 884 | def __init__(self, cond_func): |
| 885 | self.cond_func = cond_func |
| 886 | |
| 887 | def __get__(self, obj, objtype): |
| 888 | return self.cond_func() |
| 889 | |
| 890 | |
882 | 891 | def _deferredSkip(condition, reason): |
883 | 892 | def decorator(test_func): |
884 | 893 | if not (isinstance(test_func, type) and |
885 | | issubclass(test_func, TestCase)): |
| 894 | issubclass(test_func, unittest.TestCase)): |
886 | 895 | @wraps(test_func) |
887 | 896 | def skip_wrapper(*args, **kwargs): |
888 | 897 | if condition(): |
… |
… |
def _deferredSkip(condition, reason):
|
890 | 899 | return test_func(*args, **kwargs) |
891 | 900 | test_item = skip_wrapper |
892 | 901 | else: |
| 902 | # Assume a class is decorated |
893 | 903 | test_item = test_func |
| 904 | test_item.__unittest_skip__ = CheckCondition(condition) |
894 | 905 | test_item.__unittest_skip_why__ = reason |
895 | 906 | return test_item |
896 | 907 | return decorator |
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 2c2bc24..5b54a87 100644
a
|
b
|
|
2 | 2 | from __future__ import absolute_import, unicode_literals |
3 | 3 | |
4 | 4 | import unittest |
5 | | from unittest import skip |
6 | 5 | |
7 | 6 | from django.db import connection |
8 | 7 | from django.forms import EmailField, IntegerField |
9 | 8 | from django.http import HttpResponse |
10 | 9 | from django.template.loader import render_to_string |
11 | | from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature |
| 10 | from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature |
12 | 11 | from django.test.html import HTMLParseError, parse_html |
13 | 12 | from django.test.utils import CaptureQueriesContext, IgnoreAllDeprecationWarningsMixin |
14 | 13 | from django.utils import six |
… |
… |
class SkippingTestCase(TestCase):
|
27 | 26 | self.assertRaises(ValueError, test_func) |
28 | 27 | |
29 | 28 | |
| 29 | class SkippingClassTestCase(TestCase): |
| 30 | def test_skip_class_unless_db_feature(self): |
| 31 | @skipUnlessDBFeature("__class__") |
| 32 | class NotSkippedTests(unittest.TestCase): |
| 33 | def test_dummy(self): |
| 34 | return |
| 35 | |
| 36 | @skipIfDBFeature("__class__") |
| 37 | class SkippedTests(unittest.TestCase): |
| 38 | def test_will_be_skipped(self): |
| 39 | self.fail("We should never arrive here.") |
| 40 | |
| 41 | test_suite = unittest.TestSuite() |
| 42 | test_suite.addTest(NotSkippedTests('test_dummy')) |
| 43 | test_suite.addTest(SkippedTests('test_will_be_skipped')) |
| 44 | result = unittest.TextTestRunner(stream=six.StringIO()).run(test_suite) |
| 45 | self.assertEqual(result.testsRun, 2) |
| 46 | self.assertEqual(len(result.skipped), 1) |
| 47 | |
| 48 | |
30 | 49 | class AssertNumQueriesTests(TestCase): |
31 | 50 | urls = 'test_utils.urls' |
32 | 51 | |
… |
… |
class SkippingExtraTests(TestCase):
|
561 | 580 | with self.assertNumQueries(0): |
562 | 581 | super(SkippingExtraTests, self).__call__(result) |
563 | 582 | |
564 | | @skip("Fixture loading should not be performed for skipped tests.") |
| 583 | @unittest.skip("Fixture loading should not be performed for skipped tests.") |
565 | 584 | def test_fixtures_are_skipped(self): |
566 | 585 | pass |
567 | 586 | |