Closed cjwatson closed 3 years ago
It's true that maybe_a_traceback
is somewhat loose, though from its header comment it's not clear that it can be tightened up very much (in particular, it's not possible to check for the "Traceback" header because doctest preprocesses that away).
The ambiguity requires a bit more than your example as stated, though: maybe_a_traceback
is only called (directly or indirectly) if the IGNORE_EXCEPTION_MODULE_IN_PYTHON2
option flag is set. So if this does become a problem in a given doctest file, then it can be fixed by only setting that option flag on examples that are expected to raise exceptions, just as you wouldn't set IGNORE_EXCEPTION_DETAIL
on everything.
That said, at least zope.app.publisher
and zope.app.testing
fail with this, because they have tests that look like this in files where IGNORE_EXCEPTION_MODULE_IN_PYTHON2
is enabled globally:
>>> print(http(wsgi_app, r"""
... POST /@@contents.html HTTP/1.1
... Authorization: Basic bWdyOm1ncnB3
... Content-Length: 73
... Content-Type: application/x-www-form-urlencoded
...
... type_name=BrowserAdd__zope.site.folder.Folder&new_value=f1"""))
HTTP/1.1 303 See Other
...
So is the right thing to do: (a) to update these packages to set this option flag more selectively and bump zope.testing
's major version number; (b) something more clever I haven't thought of; (c) drop the idea entirely?
Maybe we can make the matching criteria more strict, since "HTTP/1.1" is clearly not a valid Python dotted name.
OK, I've given this a go. What do you think? It seems to work for me: zope.app.publisher
and zope.app.testing
pass now, and it's good enough to unblock me in Launchpad. (If only doctest
were less of an awful kludge; but I can't do much about that.)
@mgedmin Thanks, I've landed this. Would you mind doing a release?
@cjwatson, I don't mind, but I'd like to add Python 3.9 support, which also means migrating to GitHub Actions, which means I ought to learn how to use the scripts in https://github.com/zopefoundation/meta/, which will take some time.
I'd also like to grant you PyPI rights, if you would remind me what your PyPI username is?
Yeah, I had a go at that for zope.schema recently. Not too bad, mainly just involved a couple of preparatory PRs to sort out lint and such.
My PyPI username is cjwatson
.
Oops, I nearly forgot all about the release while wrangling with linters and whatnot!
4.8 is out.
When porting code from Python 2, it's sometimes necessary to handle doctests with expected output like this:
This happens when raising an exception with no arguments; there are a few cases like this in Launchpad. We can support this by making
maybe_a_traceback
slightly more liberal.