Use Python2.7 SkipTest class if available, patch up testtools if it is
[jelmer/dulwich-libgit2.git] / dulwich / tests / __init__.py
index 42a0e73d9dbaa4e31b86b03c60f11132e03346f9..943a929dd1c1476488d0a331248a40f02c9f5691 100644 (file)
 
 import unittest
 
-# XXX: Ideally we should allow other test runners as well, 
-# but unfortunately unittest doesn't have a SkipTest/TestSkipped
-# exception.
-from nose import SkipTest as TestSkipped
+try:
+    # If Python itself provides an exception, use that
+    from unittest import SkipTest as TestSkipped
+except ImportError:
+    # Check if the nose exception can be used
+    try:
+        import nose
+    except ImportError:
+        try:
+            import testtools.testcase
+        except ImportError:
+            class TestSkipped(Exception):
+                def __init__(self, msg):
+                    self.msg = msg
+        else:
+            TestSkipped = testtools.testcase.TestCase.skipException
+    else:
+        TestSkipped = nose.SkipTest
+        try:
+            import testtools.testcase
+        except ImportError:
+            pass
+        else:
+            # Make testtools use the same exception class as nose
+            testtools.testcase.TestCase.skipException = TestSkipped
+
 
 def test_suite():
     names = [