Applications Google
Menu principal

Post a Comment On: Only Python

"Monkeypatching doctest"

3 Comments -

1 – 3 of 3
Blogger Marius Gedminas said...

I disagree with the statement that testing concerns should never influence your API design. Adding verbose=False (or quiet=True) to the set_language call seems to be the cleanest solution to me.

I'd also consider doing that in a tearDown function. I don't remember if doctest.testfile supports it; I usually use doctest.DocFileSuite, collect many of them in a unittest.TestSuite, and run all with unittest.TextTestRunner.

In other circumstances I use this workaround when I want to ellipsis-match something at the beginning of the output:

>>> print; set_language(old_lang)
<BLANKLINE>
...

10:31 AM

Blogger André Roberge said...

Thanks for your suggestion for the ellipsis match at the beginning of the output. It is indeed simpler than monkeypatching doctest.

7:39 PM

Blogger Ian Bicking said...

My most involved monkeypatch yet was for doctest, to allow setting options from within a doctest.

It is located in dtopt: http://pypi.python.org/pypi/dtopt/0.1 -- I had to monkeypatch code objects in order to make it work. It's pretty horrid... I should probably put together some kind of patch to doctest itself to make this sort of stuff more doable.

3:30 PM

Spammers: none shall pass.
You can use some HTML tags, such as <b>, <i>, <a>

Comments on this blog are restricted to team members.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot