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


Groups > comp.lang.python > #89846

Re: Is this a good way to implement testing

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed.pionier.net.pl!feed.xsnews.nl!border03.ams.xsnews.nl!feeder04.ams.xsnews.nl!abp001.ams.xsnews.nl!frontend-F10-12.ams.news.kpn.nl
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.python
Subject Re: Is this a good way to implement testing
Organization Decebal Computing
References <878ud6mx4y.fsf@Equus.decebal.nl> <87383em7sn.fsf@Equus.decebal.nl> <mailman.53.1430642740.12865.python-list@python.org>
X-Face "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E
X-Homepage http://www.decebal.nl/
Date Sun, 03 May 2015 11:49:44 +0200
Message-ID <87iocakn2f.fsf@Equus.decebal.nl> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:P0Y5/x2qyOjYaqVoFHWchAGpQfQ=
MIME-Version 1.0
Content-Type text/plain
Lines 48
NNTP-Posting-Host 81.207.62.244
X-Trace 1430647209 news.kpn.nl 21078 81.207.62.244@kpn/81.207.62.244:39833
Xref csiph.com comp.lang.python:89846

Show key headers only | View raw


Op Sunday 3 May 2015 10:45 CEST schreef Peter Otten:

> Cecil Westerhof wrote:
>
>> Another question. Is it acceptable to have it in the module itself,
>> or should I put it in something like test_<module>.py? The code for
>> testing is bigger as the code for the implementation, so I am
>> leaning to putting it in a separate file.
>
> Definitely use an established testing framework instead of rolling
> your own, and definitely put it into a separate file -- by the time
> there is good coverage the test code is usually much bigger than the
> tested code.

Yep, the module already has 370 lines of testing code and only 225 of
working code. And I just started.


> Be aware that there is also doctest which scans docstrings for text
> resembling interactive Python sessions. Doctests are both tests and
> usage examples, so I think it's good to put a few of these into the
> module. Here's how it works:
>
> $ cat factorial.py
> def factorial(n):
> """Calculate the factorial 1 * 2 * ... * n.
>
>>>> factorial(0)
> 1
>>>> factorial(1)
> 1
>>>> factorial(10)
> 3628800 """ return 1 $ python3 -m doctest factorial.py
> **********************************************************************
> File "/home/peter/clpy/factorial.py", line 8, in factorial.factorial
> Failed example: factorial(10) Expected: 3628800 Got: 1
> **********************************************************************
> 1 items had failures: 1 of 3 in factorial.factorial ***Test
> Failed*** 1 failures. $

That looks very promising. But I use the test to verify the
correctness and show the performance. Is that also possible? Or should
I split those out.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 00:29 +0200
  Re: Is this a good way to implement testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-03 00:17 +0100
  Re: Is this a good way to implement testing Terry Reedy <tjreedy@udel.edu> - 2015-05-02 20:06 -0400
  Re: Is this a good way to implement testing Paul Rubin <no.email@nospam.invalid> - 2015-05-02 20:58 -0700
    Re: Is this a good way to implement testing Ben Finney <ben+python@benfinney.id.au> - 2015-05-03 14:49 +1000
  Re: Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 09:36 +0200
    Re: Is this a good way to implement testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-03 09:38 +0100
    Re: Is this a good way to implement testing Peter Otten <__peter__@web.de> - 2015-05-03 10:45 +0200
      Re: Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 11:49 +0200
        Re: Is this a good way to implement testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-03 11:21 +0100
          Re: Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 12:50 +0200
    Re: Is this a good way to implement testing Ben Finney <ben+python@benfinney.id.au> - 2015-05-03 18:52 +1000
  Re: Is this a good way to implement testing Peter Otten <__peter__@web.de> - 2015-05-03 11:22 +0200

csiph-web