doctests compatibility for python 2 & python 3
Robin Becker
robin at reportlab.com
Mon Jan 20 05:07:35 EST 2014
On 17/01/2014 21:10, Terry Reedy wrote:
> On 1/17/2014 7:14 AM, Robin Becker wrote:
>
..........
> 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 have used some 'robust' True/False equality tests and also tests which return
None or a string indicating the expected and observed outcomes eg
>
> def equalStrings(a,b,enc='utf8'):
> return a==b if type(a)==type(b) else asUnicode(a,enc)==asUnicode(b,enc)
>
> def eqCheck(r,x):
> if r!=x:
> print('Strings unequal\nexp: %s\ngot: %s' % (ascii(x),ascii(r)))
of course I needed to import ascii from the future and the asUnicode function
has to be different for python 3 and 2.
Some of our code used doctests which are discovered by a file search.
--
Robin Becker
More information about the Python-list
mailing list