[Python-Dev] Deprecate doctest?
Paul Moore
lists@morpheus.demon.co.uk
Sun, 15 Dec 2002 18:03:48 +0000
Aahz <aahz@pythoncraft.com> writes:
>> How can a test break when you change the error message text ? I'd
>> say that the test was broken: you should never rely on a particular
>> message text since these can and do change rather often.
>
> That's tricky, given that doctest is in the standard library, and
> that's exactly what doctest does. Are you advocating deprecating
> doctest?
You can write the doctest to avoid the dependency on the exact
test. As a (none too realistic) example,
>>> 1/0
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ZeroDivisionError: integer division or modulo by zero
is a bad test, because it depends on an exact text. (This one probably
isn't "bad" in practice, as I can't imagine the text changing very
often). On the other hand,
>>> try:
... 1/0
... except ZeroDivisionError:
... print "Divide by zero"
...
Divide by zero
is a good test, because it protects against such a dependency. This is
a fairly well-known type of issue with doctest, which usually shows up
in the form of reliance on a particular order of printing a
dictionary. See section 5.2.7 of the manual (Warnings).
Paul.
--
This signature intentionally left blank