Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21859
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'suppose': 0.05; 'importerror:': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'unittest': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'setup.py': 0.09; 'subject:python': 0.10; 'am,': 0.12; '2.6,': 0.16; '9:31': 0.16; 'deletions': 0.16; 'ideas?': 0.16; 'reedy': 0.16; 'try/except': 0.16; 'two.': 0.16; 'wrote:': 0.18; '2.x': 0.18; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'fine,': 0.23; 'dance': 0.24; 'code': 0.26; 'import': 0.27; 'bit': 0.28; '3.x': 0.30; 'file.': 0.31; 'idea': 0.32; 'header :User-Agent:1': 0.33; 'it?': 0.33; 'addition,': 0.34; 'test': 0.34; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'try:': 0.34; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'run': 0.37; 'but': 0.37; 'difference': 0.38; 'replace': 0.38; 'should': 0.38; 'except': 0.39; 'put': 0.40; 'to:addr:python.org': 0.40; 'matter': 0.62; 'union': 0.72; 'andrea': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Unittest2 on python 2.6 |
| Date | Sun, 18 Mar 2012 11:46:39 -0400 |
| References | <4F65E3C6.2020405@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-74-109-121-73.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| In-Reply-To | <4F65E3C6.2020405@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.783.1332085620.3037.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1332085620 news.xs4all.nl 6939 [2001:888:2000:d::a6]:48037 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21859 |
Show key headers only | View raw
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