Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100160
| From | Vincent Davis <vincent@vincentdavis.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: manually build a unittest/doctest object. |
| Date | 2015-12-08 07:31 -0700 |
| Message-ID | <mailman.68.1449585108.12405.python-list@python.org> (permalink) |
| References | <CALyJZZXeRaFxxdDK6aNSZC4xyqn082kZCGtgYBQxnBqKU-_WEg@mail.gmail.com> <n466ip$bg7$1@ger.gmane.org> |
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​.
>>> import doctest
>>> example =
doctest.Example("print('hello')\nprint('world')",want="hello\nworld")
>>> test = doctest.DocTest([example], {}, None, None, None, None)
>>> runner = doctest.DocTestRunner(verbose=True)
>>> runner.run(test)
Trying:
print('hello')
print('world')
Expecting:
hello
world
**********************************************************************
Line 1, in None
Failed example:
print('hello')
print('world')
Exception raised:
Traceback (most recent call last):
File "/Users/vincentdavis/anaconda/envs/py35/lib/python3.5/doctest.py",
line 1320, in __run
compileflags, 1), test.globs)
File "<doctest None[0]>", line 1
print('hello')
^
SyntaxError: multiple statements found while compiling a single statement
Vincent Davis
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: manually build a unittest/doctest object. Vincent Davis <vincent@vincentdavis.net> - 2015-12-08 07:31 -0700
csiph-web