pete.forman at westerngeco.com
Wed Jun 20 14:54:13 CEST 2007
Steve Howell <showell30 at yahoo.com> writes:
>> 2) assert is not the simplest example of doctest.
>> The style should be
>> >>> add_money([0.13, 0.02])
>> >>> add_money([100.01, 99.99])
>> >>> add_money([0, -13.00, 13.00])
> That's not clear cut to me. I think vertical
> conciseness has an advantage for readability, as it
> means you get to keep more "real" code on the screen.
What I meant was that doctest should be "type this into the
interpreter and you should see that". A doctest is not a unit test,
though it may form a subset of the tests. There should only be enough
doctests to enclue a human reader. Comprehensive testing should use a
larger framework. Doctests in separate files can do this but I would
use py.test, or alternatives like nose or Testoob.
>>> 2 + 2
"assert 2 + 2 == 4" is a concise way of writing a unit test but it is
not the best way to use doctest IMHO.
>> 3) which fails :-( So both the unittest and doctest
>> examples ought to
>> be redone to emphasize what they are doing
>> without getting bogged
>> down by issues of floating point representations.
> I was the one who originally posted the floating point
> example (with yet another style of unit testing, BTW),
> and I agree that the subtleties of floating point do
> kind of cloud the issue. I welcome a better example.
> What I didn't realize is that there's an actual error.
> Are you saying the program fails? On which test?
Python 2.5.1 on XP:
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pete.forman at westerngeco.com -./\.- the opinion of Schlumberger or
http://petef.port5.com -./\.- WesternGeco.
More information about the Python-list