Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'subject:error': 0.03; 'messages.': 0.05; 'stops': 0.07; 'suppose': 0.07; 'function:': 0.09; 'input,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'unittest': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '2.7': 0.14; 'diagnostic': 0.16; 'equality.': 0.16; 'expect,': 0.16; 'iterable': 0.16; 'message):': 0.16; 'nose': 0.16; 'pairs': 0.16; 'pypi.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:after': 0.16; 'subject:continue': 0.16; 'wrote:': 0.18; 'dependent': 0.19; 'normally': 0.19; 'appears': 0.22; 'header:User-Agent:1': 0.23; 'comparing': 0.24; 'instance,': 0.24; 'skip': 0.24; '(or': 0.24; 'equivalent': 0.26; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'especially': 0.30; 'gives': 0.31; 'usually': 0.31; 'assert': 0.31; 'helpful.': 0.31; 'yourself.': 0.31; 'actual': 0.34; 'subject:from': 0.34; 'except': 0.35; 'test': 0.35; 'but': 0.35; 'next': 0.36; 'subject:?': 0.36; 'should': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'does': 0.39; '(from': 0.39; 'received:71': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'failures': 0.60; 'new': 0.61; 'first': 0.61; 'such': 0.63; 'within': 0.65; 'capable': 0.67; 'abandon': 0.84; 'disappear': 0.84; 'flag.': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Switching from nose to unittest2 - how to continue after an error? Date: Mon, 25 Aug 2014 17:47:40 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-71-175-90-87.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409003278 news.xs4all.nl 2856 [2001:888:2000:d::a6]:34118 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77005 On 8/25/2014 2:13 PM, Skip Montanaro wrote: > It appears that unittest in Python 2.7 should be capable enough that I > can abandon nose in favor of python -m unittest. How do I get it to > continue past the first failure? Unittest normally stops with the first failure in a test_function. If the asserts within a function are dependent (or normally passing), that may be what you want. I know of two ways to collect multiple failures within a test function: 1. Do it yourself. For instance, let iopairs be an iterable of input, expected-output pairs for a function f. def test_f(self): failures = [] for inp, expect in iopairs: actual = f(inp) if actual != expect: failures.append((inp, expect, actual)) assertFalse(failures, 'inp, expect, actual triples' 2. Use subtests, new in 3.4, and I suspect backported in unittest2 on PyPI. This can be combined with the 1. above. Suppose two functions should both pass the test above. def test_g_h(self): for f in (g, h): with self.subTest(f=f): As for asserts (from next message): self.assertTrue is equivalent to assert, except it does not disappear with a compile flag. The other assertX methods resolve to assertTrue, but for some, such as assert raises, the equivalent in non-trivial. Even when the equivalent is trivial, the specific methods usually gives better diagnostic messages. This is especially true when comparing two non-empty collection for equality. Knowing what is a one but the the other is very helpful. -- Terry Jan Reedy