← Back to team overview

dulwich-users team mailing list archive

[PATCH] Fix unittest2 runner and reorganize test imports.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

We now support 3 scenarios, which each have their own block in
tests/__init__.py:
1. Python 2.7: use builtin unittest
2. Python 2.6 with unittest2
3. Python 2.6 with testtools (requires TESTRUNNER=testtools.run)

Tested that all of the following succeed:
2.7, make check-nocompat
2.7 + testtools, make check
2.7 + testtools, make TESTRUNNER=testtools.run check
2.6 + unittest2, make check
2.6 + unittest2 + testtools, make check
2.6 + unittest2 + testtools, make TESTRUNNER=testtools.run check

Change-Id: I379c0d58aeb6dab6814a1d74e4e8d989a017df38
---
 Makefile                  |    2 +-
 dulwich/tests/__init__.py |   20 ++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 4742d6d..932c8a9 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ PYDOCTOR ?= pydoctor
 ifeq ($(shell $(PYTHON) -c "import sys; print sys.version_info >= (2, 7)"),True)
 TESTRUNNER ?= unittest
 else
-TESTRUNNER ?= unittest2
+TESTRUNNER ?= unittest2.__main__
 endif
 RUNTEST = PYTHONPATH=.:$(PYTHONPATH) $(PYTHON) -m $(TESTRUNNER)
 
diff --git a/dulwich/tests/__init__.py b/dulwich/tests/__init__.py
index 909a4cc..93299f1 100644
--- a/dulwich/tests/__init__.py
+++ b/dulwich/tests/__init__.py
@@ -21,27 +21,27 @@
 
 import doctest
 import os
-import unittest
 import shutil
 import subprocess
 import sys
 import tempfile
 
-try:
+
+if sys.version_info >= (2, 7):
     # If Python itself provides an exception, use that
+    import unittest
     from unittest import SkipTest as TestSkipped
-except ImportError:
+    from unittest import TestCase
+else:
     try:
+        import unittest2 as unittest
         from unittest2 import SkipTest as TestSkipped
+        from unittest2 import TestCase
     except ImportError:
+        import unittest
         from testtools.testcase import TestSkipped
-
-try:
-    from testtools.testcase import TestCase
-except ImportError:
-    from unittest import TestCase
-else:
-    TestCase.skipException = TestSkipped
+        from testtools.testcase import TestCase
+        TestCase.skipException = TestSkipped
 
 
 class BlackboxTestCase(TestCase):
-- 
1.7.3.2.168.gd6b63