[issue40295] doctest handling of multiline strings is broken

2020-04-15 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

By the way Filip, you were told on the Stackoverflow page that the output was 
correct and that you were not using doctest correctly. Serhiy also hinted to 
you that you should check the output in the REPL and you falsely claimed that 
it gave the expected output, but it doesn't:

py> multiline_output()
'First line\nSecond line\n'

which is nothing like the output you put in your doctest.

This is not a bug in doctest. The very first line of the doctest documentation 
says:

The doctest module searches for pieces of text that look like
interactive Python sessions

so this is expected and documented behaviour, not a bug.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40295] doctest handling of multiline strings is broken

2020-04-15 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Have you tried calling multiline_output() in the REPL?

It does *not* show your expected output:

# expected
First line
Second line


but the string repr():

# actual
'First line\nSecond line\n'



Change your doctest to either:


>>> multiline_output()
'First line\\nSecond line\\n'

(note that you must escape the backslashes) or:

>>> print(multiline_output())
First line
Second line



Note that the "" needs to be written literally, as described here:

https://docs.python.org/3/library/doctest.html#doctest.DONT_ACCEPT_BLANKLINE

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40295] doctest handling of multiline strings is broken

2020-04-15 Thread Filip Rembiałkowski

Filip Rembiałkowski  added the comment:

Actually, the behavior does not depend on leading spaces, and test case can be 
isolated even further. Sample is attached [doctest-bugs-2.py].

--
Added file: https://bugs.python.org/file49066/doctest-bugs-2.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40295] doctest handling of multiline strings is broken

2020-04-15 Thread Filip Rembiałkowski

Filip Rembiałkowski  added the comment:

@Serhiy, Thank you for feedback. 

Yes the "testme" function (indeed trivial) works as expected - both in 
interactive Python interpreter and in script file. 

If you go to Lib/doctest.py, search for "string-identical" and debug my example 
there, you will see the problem is real.

I don't see an easy fix for the problem, I only suspect it's related to 
io.StringIO getvalue() method.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40295] doctest handling of multiline strings is broken

2020-04-15 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Did you try to run the tested function in the interactive Python interpreter? 
Did you get what you expected?

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40295] doctest handling of multiline strings is broken

2020-04-15 Thread Filip Rembiałkowski

New submission from Filip Rembiałkowski :

The doctest module does not compare multiline strings properly, as attached 
example proves. 

Tested on 2.7, 3.6 and 3.9.0a5+. (platform: Ubuntu 18.04).

Related: 
https://stackoverflow.com/questions/60956015/unexpected-errors-while-testing-python3-code-with-doctest

--
components: Library (Lib)
files: doctest-bugs.py
messages: 366554
nosy: Filip Rembiałkowski
priority: normal
severity: normal
status: open
title: doctest handling of multiline strings is broken
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49065/doctest-bugs.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com