doctests compatibility for python 2 & python 3

Albert-Jan Roskam fomcl at yahoo.com
Sat Jan 18 03:39:25 EST 2014


--------------------------------------------
On Fri, 1/17/14, Terry Reedy <tjreedy at udel.edu> wrote:

 Subject: Re: doctests compatibility for python 2 & python 3
 To: python-list at python.org
 Date: Friday, January 17, 2014, 10:10 PM
 
 On 1/17/2014 7:14 AM, Robin Becker
 wrote:
 
 > I tried this approach with a few more complicated
 outcomes and they fail
 > in python2 or 3 depending on how I try to render the
 result in the doctest.
 
 I never got how you are using doctests. There were certainly
 not meant for heavy-duty unit testing, but for testing
 combined with explanation. Section 26.2.3.7. (in 3.3)
 Warnings warns that they are fragile to even single char
 changes and suggests == as a workaround, as 'True' and
 'False' will not change. So I would not reject that option.
 

=====> I used doctests in .txt files and I converted ALL of them when I wanted to make my code work for both Python 2 and 3. I tried to fix something like a dozen of them so they'd work in Python 2.7 and 3,3. but I found it just too cumbersome and time consuming. The idea of doctest is super elegant, but it is really only meant for testable documentation (maybe with sphinx). If you'd put all the (often boring, e.g. edge cases) test cases in docstrings, the .py file will look very cluttered. One thing that I missed in unittest was Ellipsis, but: https://pypi.python.org/pypi/gocept.testing/1.6.0 offers assertEllipsis and other useful stuff.

Albert-Jan





More information about the Python-list mailing list