summaryrefslogtreecommitdiff
path: root/tests/test_utils/tests.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-08-23 18:01:33 +0200
committerClaude Paroz <claude@2xlibre.net>2014-08-26 20:03:37 +0200
commit5675eb371f8af55569602c2c6c6f275968b1ce3b (patch)
treef7cd10b21196561cc2a9b044160780a5d26b2576 /tests/test_utils/tests.py
parente02f45d5ea767b0028ecf24bb5874992eb3ca7dd (diff)
Allowed skipIf/UnlessDBFeature to accept several feature strings
Diffstat (limited to 'tests/test_utils/tests.py')
-rw-r--r--tests/test_utils/tests.py61
1 files changed, 59 insertions, 2 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index b2e4207fa5..8cd0019f7b 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -19,14 +19,71 @@ from .views import empty_response
class SkippingTestCase(TestCase):
+ def _assert_skipping(self, func, expected_exc):
+ # We cannot simply use assertRaises because a SkipTest exception will go unnoticed
+ try:
+ func()
+ except expected_exc:
+ pass
+ except Exception as e:
+ self.fail("No %s exception should have been raised for %s." % (
+ e.__class__.__name__, func.__name__))
+
def test_skip_unless_db_feature(self):
- "A test that might be skipped is actually called."
+ """
+ Testing the django.test.skipUnlessDBFeature decorator.
+ """
# Total hack, but it works, just want an attribute that's always true.
@skipUnlessDBFeature("__class__")
def test_func():
raise ValueError
- self.assertRaises(ValueError, test_func)
+ @skipUnlessDBFeature("notprovided")
+ def test_func2():
+ raise ValueError
+
+ @skipUnlessDBFeature("__class__", "__class__")
+ def test_func3():
+ raise ValueError
+
+ @skipUnlessDBFeature("__class__", "notprovided")
+ def test_func4():
+ raise ValueError
+
+ self._assert_skipping(test_func, ValueError)
+ self._assert_skipping(test_func2, unittest.SkipTest)
+ self._assert_skipping(test_func3, ValueError)
+ self._assert_skipping(test_func4, unittest.SkipTest)
+
+ def test_skip_if_db_feature(self):
+ """
+ Testing the django.test.skipIfDBFeature decorator.
+ """
+ @skipIfDBFeature("__class__")
+ def test_func():
+ raise ValueError
+
+ @skipIfDBFeature("notprovided")
+ def test_func2():
+ raise ValueError
+
+ @skipIfDBFeature("__class__", "__class__")
+ def test_func3():
+ raise ValueError
+
+ @skipIfDBFeature("__class__", "notprovided")
+ def test_func4():
+ raise ValueError
+
+ @skipIfDBFeature("notprovided", "notprovided")
+ def test_func5():
+ raise ValueError
+
+ self._assert_skipping(test_func, unittest.SkipTest)
+ self._assert_skipping(test_func2, ValueError)
+ self._assert_skipping(test_func3, unittest.SkipTest)
+ self._assert_skipping(test_func4, unittest.SkipTest)
+ self._assert_skipping(test_func5, ValueError)
class SkippingClassTestCase(TestCase):