I donβt think you understood how doctest works. It does not check whether the output is somehow "equivalent", it checks whether the output is identical (only with very minor possible options, for example using ellipsis). From the documentation:
The doctest module doctest for pieces of text that look like interactive Python sessions, and then runs those sessions to make sure they work exactly as shown.
Doctest matches output ( not a string literal, python expression, or something else. Source bytes) with the contents of the example you provided. Since he does not know that the text between quotation marks is a string literal, he cannot interpret it the way you want.
In other words: the only thing you can do is simply put all the output on one line, as in:
>>> get_string(1, 2) 'This is \n\na long \n string with new space characters \n\n'
If the output of this is too long, you can try changing the example to create a shorter string (for example, cut it into 50 characters: get_string(1, 2)[:50] ). If you look at the teachings of different projects, you will find different hacks to make the doctrines more readable, while providing a reliable conclusion.
source share