doctest exceptoin pickiness (was RE: eval(repr(x)) == x)
Alex Martelli
aleax at aleax.it
Mon Jan 28 03:25:13 EST 2002
"Tim Peters" <tim_one at email.msn.com> wrote in message
news:mailman.1012184626.10941.python-list at python.org...
...
> > repr being inverse. The *only* p.i.t.a with doctest is that with every
> > Python release the exact wording of some exception or other changes,
>
> Also pretty common for AttributeErrors to turn into TypeErrors, and vice
> versa (alas -- it's a fuzzy distinction!).
I wouldn't mind having to handle THAT with a try/except in the
docstring example -- it may be "pretty common", but my impression
is that it bites me with a frequency an order of magnitude rarer
than the more innocuous "change wording in error message" issue.
> > very impractical for test suites intended to survive from one Python
> > version to the next, or work across two Python versions. But that
> > wouldn't be fixed by any change to repr...
>
> Guido whines about this too, and I always tell him to grow up <wink>.
Since
> doctest's initial and still-best purpose is to verify examples in
> docstrings, and users (rightfully) call it "a bug" when canned examples
> clash with what they actually see, doctest deliberately complains when a
> canned error message gets out of synch with reality. It would be easy to
> relax that, but I wouldn't want to make tolerance the default behavior.
I'd be perfectly happy with using some switch or option, with doctest
defaulting to its current must-match-identically behavior (which, as you
say, may well be optimal for its "initial and still-best purpose") but
easily switched into something a little bit more tolerant (which may be
optimal for its "current and secondary purpose" of making it easy and
fun, rather than a chore, to develop unit tests).
> Ensuring just "does or does not raise *some* exception" would be the
easiest
> alternative to provide. An insane extension could invent markup tagging
I'd be quite happy with a "slightly tolerant mode" that matches the
type but not necessarily the stringvalue of the exception.
> change over time?)! For doctest's primary purpose, making life difficult
> when fed poor examples is "a feature".
Right. But for its secondary purpose (which is in fact the one I use
it and proselitize it for) it's a "minor to medium" annoyance instead.
Alex
More information about the Python-list
mailing list