[Python-Dev] Unittest/doctest formatting differences in 2.7a1?

Lennart Regebro lregebro at jarn.com
Wed Dec 9 18:23:11 CET 2009

On Wed, Dec 9, 2009 at 17:43, Fred Drake <fdrake at acm.org> wrote:
> On Wed, Dec 9, 2009 at 11:29 AM, Benjamin Peterson <benjamin at python.org> wrote:
>> Could you mention what specific changes are causing problems?
> I'd be glad to head Lennart confirm this, but I suspect this is
> primarily changes in exception messages; 2.7 in many places provides
> better messages.

Ouch, that is *not* good. That's going to break tests for all
doctests, not just zope.testing (which obviously is a special case). I
know PythonZope 3 has changes there do, and that's annoying in itself
but acceptable since Python 3 doesn't promise to be backwards
compatible, but a similar change in 2.7 is something I would consider
a bug.

> I found some of this with a few of the Zope-related packages that I
> tried testing under pre-2.7 versions of Python.

You remember which one?

>  If this is what Lennart's referring to,

No, the only modules I've run under 2.7 so far is zope.interface which
passes the tests, zope.exception which has no doctests and zope.event,
which has 4 lines of code. :)

And zope.testing, then, which is massive and had loads and loads of
tests, mostly doctests.

> I consider this to be a problem with the tests.

If the exception format has changed, I consider it a bug. Possibly a
bug in doctest, as the only way to test for exceptions in that case is
like this:

    >>> try:
    ...     throw_an_exception()
    ...     print "Did not throw the exception"
    ... except DesiredException:
    ...     print "passed"

And that frankly is rather ugly. That's how I have done with doctests
when porting to Python 3 so far. I don't think it's a good idea to
require it for Python 2.7 as well.

> Evolving the tests to avoid depending on these sorts of implementation
> details is reasonable, IMO, and cuold even be considered a bugfix by
> the Zope community.

Evolving doctest.py so it can handle this by itself would be
considered a bugfix by me. :)
Lennart Regebro: Python, Zope, Plone, Grok
+33 661 58 14 64

More information about the Python-Dev mailing list