Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100247 > unrolled thread

Re: python unit test frame work

Started byCameron Simpson <cs@zip.com.au>
First post2015-12-11 11:40 +1100
Last post2015-12-11 11:40 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: python unit test frame work Cameron Simpson <cs@zip.com.au> - 2015-12-11 11:40 +1100

#100247 — Re: python unit test frame work

FromCameron Simpson <cs@zip.com.au>
Date2015-12-11 11:40 +1100
SubjectRe: python unit test frame work
Message-ID<mailman.123.1449798669.12405.python-list@python.org>
On 11Dec2015 04:05, Ganesh Pal <ganesh1pal@gmail.com> wrote:
>On Dec 11, 2015 3:57 AM, "Ganesh Pal" <ganesh1pal@gmail.com> 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 <cs@zip.com.au>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web