diff --git a/django/test/testcases.py b/django/test/testcases.py
index 95e751d..4362901 100644
a
|
b
|
class TestCase(TransactionTestCase):
|
846 | 846 | transaction.leave_transaction_management(using=db) |
847 | 847 | |
848 | 848 | |
| 849 | class CheckCondition(object): |
| 850 | """ Descriptor class for deferred condition checking """ |
| 851 | def __init__(self, cond_func): |
| 852 | self.cond_func = cond_func |
| 853 | def __get__(self, obj, objtype): |
| 854 | return self.cond_func() |
| 855 | |
849 | 856 | def _deferredSkip(condition, reason): |
850 | 857 | def decorator(test_func): |
851 | 858 | if not (isinstance(test_func, type) and |
852 | | issubclass(test_func, TestCase)): |
| 859 | issubclass(test_func, ut2.TestCase)): |
853 | 860 | @wraps(test_func) |
854 | 861 | def skip_wrapper(*args, **kwargs): |
855 | 862 | if condition(): |
856 | 863 | raise ut2.SkipTest(reason) |
857 | 864 | return test_func(*args, **kwargs) |
858 | 865 | test_item = skip_wrapper |
| 866 | test_item.__unittest_skip_why__ = reason |
| 867 | return test_item |
859 | 868 | else: |
860 | | test_item = test_func |
861 | | test_item.__unittest_skip_why__ = reason |
862 | | return test_item |
| 869 | # Assume a class is decorated |
| 870 | test_func.__unittest_skip__ = CheckCondition(condition) |
| 871 | test_func.__unittest_skip_why__ = reason |
| 872 | return test_func |
863 | 873 | return decorator |
864 | 874 | |
865 | 875 | |
diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py
index 46479eb..f37d94d 100644
a
|
b
|
|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from __future__ import absolute_import, unicode_literals |
3 | 3 | |
| 4 | from io import BytesIO |
| 5 | |
4 | 6 | from django.forms import EmailField, IntegerField |
5 | 7 | from django.http import HttpResponse |
6 | 8 | from django.template.loader import render_to_string |
7 | | from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature |
8 | | from django.utils.unittest import skip |
| 9 | from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature |
| 10 | from django.utils import unittest |
9 | 11 | |
10 | 12 | from .models import Person |
11 | 13 | |
… |
… |
class SkippingTestCase(TestCase):
|
21 | 23 | self.assertRaises(ValueError, test_func) |
22 | 24 | |
23 | 25 | |
| 26 | class SkippingClassTestCase(TestCase): |
| 27 | def test_skip_class_unless_db_feature(self): |
| 28 | @skipUnlessDBFeature("__class__") |
| 29 | class NotSkippedTests(unittest.TestCase): |
| 30 | def test_dummy(self): |
| 31 | return |
| 32 | |
| 33 | @skipIfDBFeature("__class__") |
| 34 | class SkippedTests(unittest.TestCase): |
| 35 | def test_will_be_skipped(self): |
| 36 | self.fail("We should never arrive here.") |
| 37 | |
| 38 | test_suite = unittest.TestSuite() |
| 39 | test_suite.addTest(NotSkippedTests('test_dummy')) |
| 40 | test_suite.addTest(SkippedTests('test_will_be_skipped')) |
| 41 | result = unittest.TextTestRunner(stream=BytesIO()).run(test_suite) |
| 42 | self.assertEqual(result.testsRun, 2) |
| 43 | self.assertEqual(len(result.skipped), 1) |
| 44 | |
| 45 | |
24 | 46 | class AssertNumQueriesTests(TestCase): |
25 | 47 | urls = 'regressiontests.test_utils.urls' |
26 | 48 | |
… |
… |
class SkippingExtraTests(TestCase):
|
458 | 480 | with self.assertNumQueries(0): |
459 | 481 | super(SkippingExtraTests, self).__call__(result) |
460 | 482 | |
461 | | @skip("Fixture loading should not be performed for skipped tests.") |
| 483 | @unittest.skip("Fixture loading should not be performed for skipped tests.") |
462 | 484 | def test_fixtures_are_skipped(self): |
463 | 485 | pass |
464 | 486 | |