Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100160 > unrolled thread

Re: manually build a unittest/doctest object.

Started byVincent Davis <vincent@vincentdavis.net>
First post2015-12-08 07:31 -0700
Last post2015-12-08 07:31 -0700
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.


Contents

  Re: manually build a unittest/doctest object. Vincent Davis <vincent@vincentdavis.net> - 2015-12-08 07:31 -0700

#100160 — Re: manually build a unittest/doctest object.

FromVincent Davis <vincent@vincentdavis.net>
Date2015-12-08 07:31 -0700
SubjectRe: manually build a unittest/doctest object.
Message-ID<mailman.68.1449585108.12405.python-list@python.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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web