On 07/15/2010 11:14 PM, pyt...@bdurham.com wrote: > I'm working with some Python 2.6 code that is using the doctest module > for unittests. > > I tried adding tests whose code and results required newlines (\n). > Apparently newlines in string constants breaks the doctest code. > > Any workarounds other than using another char for newlines and wrapping > all my strings with .replace( someChar, chr(10) )?
Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings. Remember that the two following strings are identical: """a b""" """a\nb""" As are these two: r"\n" "\\n" Anyway, you need to escape the backslash if you want backslash-n to be in your docstring. Otherwise you'll get a newline like any other newline, not a character sequence doctest can eval() to a newline while processing. -- http://mail.python.org/mailman/listinfo/python-list