[FRPythoneers] Doctest

Sean Reifschneider jafo at tummy.com
Thu Jul 26 14:29:15 MDT 2001


On Thu, Jul 26, 2001 at 08:08:59AM -0600, Jim Vickroy wrote:
>If you do not like an OO framework for testing, PyUnit probably should not
>be your tool of choice.

In PyUnit, you the syntax for specifying that a test's failure is
non-fatal is:

   def testSomeTestName(self):

which to me doesn't seem overly OO.  It reminds me of the people who want a
short-hand for doing something and so they overload an operator.  "Adding a
string to this NNTP class sets the newsgroup you're in."

Obviously, I'd rather see "failIfNotEqual(cmp('a', 'b'), -1, fatal = 0)",
where a test failure is flagged as being non-fatal using "fatal = 0" than
"def testFunctionName(self):".

The best case that comes to me for not using the function semantics is if
you want to run the test against a large list of data.  For example, I was
writing some code which did a comparison between RPM version strings, and
for testing I was considering generating a table based on the output of the
C implementation so I could refactor it in Python.  I was going to generate
a list of thousands of these strings and the expected results based on
real-world version strings on a distributions.

In PyUnit, if I were to do:

   for lhs, rhs, expected in rpmVersTestList:
      test.failIfNotEqual(rpmverscmp(lhs, rhs), expected)

it's going to terminate at the first one found, and in fact there doesn't
seem to be a real way to get them all to run short of doing something like
the following in the test setup:

   i = 0
   for lhs, rhs, expected in rpmVersTestList:
      setattr(self, 'test%04d',
            lambda test, x = lhs, y = rhs, z = expected:
            test.failIfNotEqual(x, y, z))

In this case, the most important data I can get from the test-suite is not
that one of the tests failed, but the pattern of WHICH tests failed.  That
allows me to determine that, for example, all tests which had a release
name of the format "number-string-number" were failing.  Or version strings
that both have a trailing alpha string have the logic reversed.

Evelyn asserts that this is regression testing, not unit testing, so maybe
what I want to do just isn't suitable for the unittest module.

Guess you don't need any more of Uche and I tag-teaming you...  I do agree
with him that supporting people who test both ways would be nice though...

Thanks for the pointers.

Sean
-- 
 We are all in the gutter, but some of us are looking at the stars.
                 -- Oscar Wilde
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python



More information about the FRPythoneers mailing list