Vincent Davis wrote: > On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__pete...@web.de> wrote: > >> >>> import doctest >> >>> example = doctest.Example( >> ... "print('hello world')\n", >> ... want="hello world\n") >> >>> test = doctest.DocTest([example], {}, None, None, None, None) >> >>> runner = doctest.DocTestRunner(verbose=True) >> >>> runner.run(test) >> Trying: >> print('hello world') >> Expecting: >> hello world >> ok >> TestResults(failed=0, attempted=1) >> > > ​and now how to do a multi line statement​.
doctest doesn't do tests with multiple *statements.* A docstring like """ >>> x = 42 >>> print(x) 42 """ is broken into two examples: >> import doctest >>> p = doctest.DocTestParser() >>> doctest.Example.__repr__ = lambda self: "Example(source={0.source!r}, want={0.want!r})".format(self) >>> p.get_examples(""" ... >>> x = 42 ... >>> print(x) ... 42 ... """) [Example(source='x = 42\n', want=''), Example(source='print(x)\n', want='42\n')] -- https://mail.python.org/mailman/listinfo/python-list