Is it possible to work with multiline statements using python doctest?
For example, the following is not working in doctest:
>>> for s in [1,2,3]: ... for t in [4,5,6]: ... print(s*t)
I need the above three statements to be executed from doctest.
Edit: my answer is wrong; see the comment from
raacer below. I can’t delete this because it’s the accepted answer.
That’s not how
doctest works. It tests an expression that evaluates to a value; it does not capture and test output. So what you want to do is create a list that can be tested, which you can easily do in a single line using a list comprehension:
>>> [s * t for s in [1, 2, 3] for t in [4, 5, 6]] [4, 5, 6, 8, 10, 12, 12, 15, 18]