← Back to team overview

dulwich-users team mailing list archive

[RFC/PATCH] unittest2 fix

 

I've tested this by running make check in the following configurations:
-2.6 + unittest2
-2.6 + unittest2 + testtools
-2.7
-2.7 + testtools

I'm not sure if we want to support 2.6 without unittest2. Both with and
without this patch, even if you set the RUNTEST to something else (e.g.
nosetests), it fails with an ImportError in tests/__init__.py.

I'm also not sure how to run a single test method from the command line with
this new setup. I used to be able to do 'nosetests
dulwich.tests.test_foo:BarTest.test_baz', but something about the test
suites has changed in a way that prevents nose from discovering the test_foo
module. If my issue is with the nose command line, maybe Augie can help. Or
we could add another target to the Makefile; I don't really care either way.

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..58e6b89 100644
--- a/dulwich/tests/__init__.py
+++ b/dulwich/tests/__init__.py
@@ -21,27 +21,30 @@

 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
     except ImportError:
+        import unittest
         from testtools.testcase import TestSkipped
+        TestCase.skipException = TestSkipped

 try:
     from testtools.testcase import TestCase
-except ImportError:
-    from unittest import TestCase
-else:
     TestCase.skipException = TestSkipped
+except ImportError:
+    TestCase = unittest.TestCase


 class BlackboxTestCase(TestCase):
--
1.7.3.2.168.gd6b63

Follow ups