[Python-3000] doctest portability

Stefan Behnel stefan_ml at behnel.de
Sat May 31 15:36:58 CEST 2008


Hi,

I currently use a bunch of work-arounds for doctests in lxml's test suite to
make them work in Py3. I converted most tests to a mix of Py2 and Py3 syntax
(e.g. using both u'' and b'' literals), and most of the runtime work is done
using regular expressions that convert the except-as syntax, strip package
names from tracebacks and translate bytes/str output between Py2 and Py3
syntax/repr.

I know, I could use the lib2to3 package, but it a) is a one-way tool in the
wrong direction if you have to distinguish bytes/str literals, b) lacks
configurability stating exactly what changes need to be done and c) seemed
harder to set up for doctests than doing the conversion by hand. It would be
really nice if the doctest module had a simple option that specified if the
doctests of a test suite are in Py2 or Py3 syntax, and then just did the right
thing under Py3 (and maybe also 2.6). Otherwise, a lot more people than just
myself will have a hard time getting their test suites to run in Py3, which is
basically the only way to sanely migrate code.

Stefan



More information about the Python-3000 mailing list