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


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

Re: manually build a unittest/doctest object.

Started byPeter Otten <__peter__@web.de>
First post2015-12-08 10:06 +0100
Last post2015-12-08 10:06 +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.


Contents

  Re: manually build a unittest/doctest object. Peter Otten <__peter__@web.de> - 2015-12-08 10:06 +0100

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

FromPeter Otten <__peter__@web.de>
Date2015-12-08 10:06 +0100
SubjectRe: manually build a unittest/doctest object.
Message-ID<mailman.53.1449565611.12405.python-list@python.org>
Vincent Davis wrote:

> If I have a string that is python code, for example
> mycode = "print('hello world')"
> myresult = "hello world"
> How can a "manually" build a unittest (doctest) and test I get myresult
> 
> I have attempted to build a doctest but that is not working.
> e = doctest.Example(source="print('hello world')/n", want="hello world\n")
> t = doctest.DocTestRunner()
> t.run(e)

There seems to be one intermediate step missing:

example --> doctest --> runner

>>> 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)

But why would you want to do that?

[toc] | [standalone]


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


csiph-web