[Tutor] still nosing around

Walter Prins wprins at gmail.com
Wed May 22 13:37:34 CEST 2013


Hi,

On 22 May 2013 05:26, Jim Mooney <cybervigilante at gmail.com> wrote:

> But that brings up a point. Does this mean that if I have to test a
> module with a lot of subroutines I have to rename every subroutine
> with 'test' appended?
>

Some quick comments for what it's worth: (One of) the points about nose is
to make lessen the overhead needed to write tests.  With unittest, you have
to create a subclass of unittest.Testcase in order to identify and package
tests for the test framework, and  manually organise them into suites.
 This is fine, but slightly burdensome if all you want is to write a
function or functions that tests another function or functions (maybe
working still in just one single file at that point, as it were, on a
single function or so.)

Nose allows you to do this, e.g. just start writing tests with as little
friction/resistance as possible.  But there's a question:  How is the test
runner now supposed to "know" whether an arbitrary function in a module is
in fact a test?  With unittest, the test framework "knows" (get it) by the
fact that tests are descended from a common base class.  But with an
arbitrary function, how should the test framework know?

So to answer your question: In short, yes, you have to let nose know
whether a given piece of code is a test.  Either include the word "test" in
the function name either prefixed or postfixed as "_test" as you asked Or
you can do it like unittest requires, e.g. create a test class descended
from unittest.Testcase, in which case your method names then don't matter
IIRC.  You may have read this already, but the relevant documentation page:
https://nose.readthedocs.org/en/latest/writing_tests.html

Aside, doctest answers/approaches this same question by reading IIRC
docstring entries for classes, methods or modules (?) and assumes that text
that looks like  python interpreter styled input/output sequences defines
test input/output sequences.

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130522/011a57ce/attachment.html>


More information about the Tutor mailing list