You probably did something wrong. Below is the correct example.
test.py:
"""
>>> for s in [1,2,3]:
... for t in [4,5,6]:
... print s*t
4
5
6
8
10
12
12
15
18
"""
It works just fine:
$ python -m doctest -v test.py
Trying:
for s in [1,2,3]:
for t in [4,5,6]:
print s*t
Expecting:
4
5
6
8
10
12
12
15
18
ok
1 items had no tests:
test.print_and_return
1 items passed all tests:
1 tests in test
1 tests in 2 items.
1 passed and 0 failed.
Test passed.
Also please note that doctest
captures both the return value and the output:
def print_and_return():
"""
>>> print_and_return()
1
2
"""
print(1)
return 2
Any expected output must immediately follow the final '>>> ' or '... '
line containing the code, and the expected output (if any) extends to
the next '>>> ' or all-whitespace line.
https://docs.python.org/2/library/doctest.html#how-it-works