Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'test,': 0.05; 'tests.': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'cc:addr:python-list': 0.15; 'exception.': 0.16; 'obsolete': 0.16; 'raises': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:instance': 0.16; 'subject:type': 0.16; 'subject:unittest': 0.16; 'test".': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'so.': 0.16; 'argument': 0.18; 'changes': 0.19; 'fix': 0.20; 'wrote:': 0.21; '(not': 0.22; 'detect': 0.22; 'fine,': 0.22; 'passing': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'right.': 0.23; 'test': 0.24; 'cc:no real name:2**0': 0.26; 'cc:addr:python.org': 0.27; 'subject:with': 0.28; 'code': 0.29; 'decide': 0.29; 'raise': 0.30; 'tests': 0.30; 'cc:2**0': 0.31; 'leave': 0.34; 'too': 0.35; 'two': 0.35; 'should': 0.35; 'explain': 0.35; 'actually': 0.35; 'but': 0.36; 'does': 0.36; 'and/or': 0.37; 'being': 0.39; 'how': 0.40; 'nor': 0.60; 'single': 0.61; 'received:userid': 0.61; 'more': 0.63; 'personal': 0.65; 'remove': 0.65; 'believe': 0.67; 'due': 0.68; 'decision': 0.69; 'approach,': 0.84; 'finely': 0.84; 'so:': 0.84 Date: Fri, 30 Mar 2012 10:45:39 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2585 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333132489 news.xs4all.nl 6911 [2001:888:2000:d::a6]:46282 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22389 Steven D'Aprano wrote: > To the degree that the decision of how finely to slice tests is a matter > of personal judgement and/or taste, I was wrong to say "that is not the > right way". I should have said "that is not how I would do that test". > > I believe that a single test is too coarse, and three or more tests is > too fine, but two tests is just right. Let me explain how I come to that > judgement. > > If you take a test-driven development approach, the right way to test > this is to write testFooWillFail once you decide that foo() should raise > MyException but before foo() actually does so. You would write the test, > the test would fail, and you would fix foo() to ensure it raises the > exception. Then you leave the now passing test in place to detect > regressions. > > Then you do the same for the errorcode. Hence two tests. [snip] > So: never remove tests just because they are redundant. Only remove them > when they are obsolete due to changes in the code being tested. Very persuasive argument -- I now find myself disposed to writing two tests (not three, nor five ;). ~Ethan~