Преглед на файлове

Use Python2.7 SkipTest class if available, patch up testtools if it is
installed so testtools and subunit can report skips properly.

Jelmer Vernooij преди 15 години
родител
ревизия
b74cc6c034
променени са 1 файла, в които са добавени 26 реда и са изтрити 4 реда
  1. 26 4
      dulwich/tests/__init__.py

+ 26 - 4
dulwich/tests/__init__.py

@@ -21,10 +21,32 @@
 
 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 = [