dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00439
Re: [RFC/PATCH] unittest2 fix
On Tue, Dec 28, 2010 at 01:41:17PM -0800, Dave Borowitz wrote:
> 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.
s/RUNTEST/TESTRUNNER/ ?
Setting TESTRUNNER to testtools.run and PYTHON to python2.6 I was able to get the
tests to pass in current trunk.
> 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
^^ I think this makes us no longer patch the testtools' TestCase, which its
test runner will use when checking if an exception was a test exception.
> try:
> from testtools.testcase import TestCase
> -except ImportError:
> - from unittest import TestCase
> -else:
> TestCase.skipException = TestSkipped
> +except ImportError:
> + TestCase = unittest.TestCase
This seems unnecessarily complex - I think we should be able to fold it into
the try/except above.
Cheers,
Jelmer
Follow ups
References