Interlude - Write Python Doctests interactive
erstellt von Jens W. Klein
—
01.02.2009 00:40
A shell/ console for doctests.
Python offers simple methods to enter interactive mode. Some years ago I thought its a good idea to use it while writing doctests. On a 5h train ride from Innsbruck to Vienna I digged into pythons code and doctest package and married both. Result was a tiny code snippet I cut'n'pasted all the time into my tests. Also ArchGenXML generates it when generating test-stubs.
Now I released it under the name interlude on PyPI: http://pypi.python.org/pypi/interlude
After easy_install it - or include in buildout usage is now dumb easy:
- import interlude
- Give your doctest.DocFileSuite( ... ) an kwarg globs of type dict with key 'interact' and value interlude.interact, like:
import interlude def test_suite(): return unittest.TestSuite([ doctest.DocFileSuite( 'interludetest.txt', globs=dict(interact=interlude.interact, ), ),]) - in your doctest add a >>> interact(locals())
This results in a interpreter shell and looks like:
jensens@minime:~/DEV/interludetest/$ ./bin/test Running tests at level 1 Installing interludetest ... done (0.007s) Running unit tests: Running: ................... ===================================================== Interlude DocTest Interactive Console - (c) BlueDynamics Alliance Note: You have the same locals available as in your test-case. Ctrl-D ends session and continues testing. >>> seqDT[0] datetime.datetime(2008, 8, 26, 23, 59, tzinfo=<UTC>) >>> [pressed Ctrl-D] end of DocTest Interactive Console session ===================================================== Ran 19 tests with 0 failures and 0 errors in 78.630 seconds. jensens@minime:~/DEV/interludetest/$

thanks
I use doctest quite intensively and I will look at this tool.