Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21859
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Unittest2 on python 2.6 |
| Date | 2012-03-18 11:46 -0400 |
| References | <4F65E3C6.2020405@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.783.1332085620.3037.python-list@python.org> (permalink) |
On 3/18/2012 9:31 AM, Andrea Crotti wrote:
> Suppose we want to use the unittest from Python 2.7, but also want to
> support Python 2.6,
> what is the best way to do it?
>
> The solution used now is to have in setup.py
>
> if sys.version < '2.7':
> tests_require.append('unittest2')
>
> and then in every test file
>
> try:
> import unittest2 as unittest
> except ImportError:
> import unittest
>
> and it should work just fine, but it's a bit verbose to have this
> try/except dance everywhere..
> Any ideas?
1. If the difference between unittest and unittest2 is strictly a matter
of deletions and addition, replace unittest with the union of the two.
2. Put the try/except dance in a compat file. Then everywhere else 'from
compat import unittest'. This idea is one of those used to write code
that will run on both 2.x and 3.x
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Unittest2 on python 2.6 Terry Reedy <tjreedy@udel.edu> - 2012-03-18 11:46 -0400
csiph-web