Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100168 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2015-12-08 16:31 +0100 |
| Last post | 2015-12-08 16:31 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: manually build a unittest/doctest object. Peter Otten <__peter__@web.de> - 2015-12-08 16:31 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-12-08 16:31 +0100 |
| Subject | Re: manually build a unittest/doctest object. |
| Message-ID | <mailman.73.1449588710.12405.python-list@python.org> |
Vincent Davis wrote:
> On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__peter__@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')]
Back to top | Article view | comp.lang.python
csiph-web