diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-07-19 20:30:14 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-07-19 20:30:14 +0200 |
| commit | 6d52844b9b3c0bd18eea03ac9dc499782b84c36b (patch) | |
| tree | 8df4e2609d5fc8b1b1ea68ff422d90e776693e8c /tests/test_utils/tests.py | |
| parent | a269ea4fe0a9a7195f1bd8bf5d462f48c226d525 (diff) | |
Fixed #18551 -- Enabled skipIfDBFeature/skipUnlessDBFeature to decorate a class
Thanks Tim Graham for the review and improved patch.
Diffstat (limited to 'tests/test_utils/tests.py')
| -rw-r--r-- | tests/test_utils/tests.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 2c2bc24d72..24aa433dd3 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -2,13 +2,12 @@ from __future__ import absolute_import, unicode_literals import unittest -from unittest import skip from django.db import connection from django.forms import EmailField, IntegerField from django.http import HttpResponse from django.template.loader import render_to_string -from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature +from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test.html import HTMLParseError, parse_html from django.test.utils import CaptureQueriesContext, IgnoreAllDeprecationWarningsMixin from django.utils import six @@ -27,6 +26,29 @@ class SkippingTestCase(TestCase): self.assertRaises(ValueError, test_func) +class SkippingClassTestCase(TestCase): + def test_skip_class_unless_db_feature(self): + @skipUnlessDBFeature("__class__") + class NotSkippedTests(unittest.TestCase): + def test_dummy(self): + return + + @skipIfDBFeature("__class__") + class SkippedTests(unittest.TestCase): + def test_will_be_skipped(self): + self.fail("We should never arrive here.") + + test_suite = unittest.TestSuite() + test_suite.addTest(NotSkippedTests('test_dummy')) + try: + test_suite.addTest(SkippedTests('test_will_be_skipped')) + except unittest.SkipTest: + self.fail("SkipTest should not be raised at this stage") + result = unittest.TextTestRunner(stream=six.StringIO()).run(test_suite) + self.assertEqual(result.testsRun, 2) + self.assertEqual(len(result.skipped), 1) + + class AssertNumQueriesTests(TestCase): urls = 'test_utils.urls' @@ -561,7 +583,7 @@ class SkippingExtraTests(TestCase): with self.assertNumQueries(0): super(SkippingExtraTests, self).__call__(result) - @skip("Fixture loading should not be performed for skipped tests.") + @unittest.skip("Fixture loading should not be performed for skipped tests.") def test_fixtures_are_skipped(self): pass |
