[Python-Dev] Doctest and Footnotes
Fred Drake
fred at zope.com
Tue Jul 11 20:52:29 CEST 2006
On Tuesday 11 July 2006 14:37, Alexander Belopolsky wrote:
> That's true, but you cannot test an object method without creating the
> object first.
True. How the object is created can vary; if the creation affects the
expected behavior in any way, you'll need be careful about how the
constructor is called for that test. In fact, __init__ isn't always the
desired constructor; some other class method might be used.
> For the main cases you would want the object definition
> close to the test for the benefit of people who do pydoc Foo.bar, but
> for corner cases it is better to have a predefined set of exotic
> objects available under descriptive names.
This is subjective. That's certainly one way of organizing the tests, and
I've no problem with it, but some of us use a more narrative approach, and we
don't want our test structure to be constrained by the layout of the source
code.
Gary's idea about using footnotes to aid in structuring tests is only about
enabling a particular approach to structure, not about requiring it. If it
doesn't fit your needs, there's certainly no need to use it. For more
elaborate test structures, I suspect it will prove quite useful. I also
expect it will be more helpful for tests in separate text files than for
tests embedded in source code.
-Fred
--
Fred L. Drake, Jr. <fred at zope.com>
Zope Corporation
More information about the Python-Dev
mailing list