Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson Newsgroups: comp.lang.python Subject: Re: python unit test frame work Date: Fri, 11 Dec 2015 11:40:21 +1100 Lines: 35 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de gkumI/+2D1Ly+/9ZjDbXRgsbGoQczlLS9h+YfrLA9A+w== 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; 'failing': 0.05; 'exit': 0.07; 'subject:test': 0.07; 'unittest': 0.07; 'cc:addr:python- list': 0.09; 'abort': 0.09; 'tends': 0.09; 'python': 0.10; 'def': 0.13; 'subject:python': 0.14; '>on': 0.16; 'docstring': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'lexical': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'substitute': 0.16; 'this)': 0.16; 'wrote:': 0.16; 'later': 0.16; 'test.': 0.18; 'tests.': 0.18; 'tests': 0.18; '2015': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; 'cc:2**1': 0.22; 'terminate': 0.22; 'cheers,': 0.22; 'cc:no real name:2**0': 0.22; 'am,': 0.23; 'seems': 0.23; 'dec': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'testing': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'command': 0.26; 'sense': 0.26; 'earlier': 0.27; 'followed': 0.27; 'module.': 0.27; 'tend': 0.27; 'checks': 0.30; "can't": 0.32; 'continuing': 0.32; 'run': 0.33; 'point,': 0.33; 'suit': 0.33; 'execution': 0.35; 'fail': 0.35; "isn't": 0.35; 'unit': 0.35; 'subject:work': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'charset:us-ascii': 0.37; 'drop': 0.38; 'names': 0.38; 'several': 0.38; 'end': 0.39; 'means': 0.39; 'test': 0.39; 'does': 0.39; 'application': 0.39; 'some': 0.40; 'your': 0.60; 'real': 0.62; 'more': 0.63; 'here:': 0.63; 'you.': 0.64; 'cameron': 0.66; 'received:61': 0.72; 'facilities': 0.72; 'hand': 0.82; 'observed': 0.84; 'habit': 0.91; 'hand,': 0.97 X-Authentication-Info: Submitted using ID cskk@bigpond.com X-Authority-Analysis: v=2.0 cv=AdUz7grG c=1 sm=1 a=YbPRTKbcWhWXF4qpG6u1xw==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=wUQvQvOEmiQA:10 a=pGLkceISAAAA:8 a=Z--WS0WmLj4AHcNK1VMA:9 a=CjuIK1q_8ugA:10 a=YbPRTKbcWhWXF4qpG6u1xw==:117 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100247 On 11Dec2015 04:05, Ganesh Pal wrote: >On Dec 11, 2015 3:57 AM, "Ganesh Pal" wrote: >> > Drop the habit to sprinkle sys.exit() all over the place. A well-behaved >> > application has one exit point, at the end of the main module. >> >I was using sys.exit() as the means to stop the execution or terminate the >program. I can't think of an alternative for my case : >I have multiple checks if I don't meet them continuing with the main >program doesn't make sense First, as Ben remarks, if one test _depends_ on an earlier one then it isn't a real unit test. On the other hand, if you simply have some simple tests followed by more complex tests (I have several like this) you have two facilities to help you. Firstly, I have observed that unittest tends to run tests in lexical order, so I tend to name the test methods like this: def test00minimalist(self): def test01minimalPlusOneThing(self): ... def test20somethingComplex(self): and on the command line when you are hand testing things: python -m cs.venti.tcp_tests -v -f Of course, substitute your module name. The -v recites the test names and docstring first line as Peter has mentioned. The -f causes the etst suit to fail on the first test failure, and does not run the later tests. That seems to cover what you want here: abort on the simplest failing test. Cheers, Cameron Simpson