[py-dev] Backtracking on doctest

Ian Bicking ianb at colorstudy.com
Fri May 13 21:00:14 CEST 2005


Well, now I'm starting to backtrack.  After I extended my test while 
adding new features, I looked back over my doctests and realized they 
were pretty pointless.  For brevity, most of my code no longer produced 
output at all, but instead was doing internal inserts.  If I didn't have 
a wrapper around my application for testing this might not have been 
feasible, but without a wrapper the testing wouldn't be feasible.

Anyway, I converted it to a normal py.test test.  It seems much more 
reasonable.  I'm a little sad that it's not sitting right next to the 
servlet that it tests -- I liked that the tests were in a docstring 
(though they were also becoming rather long-winded, so maybe that's not 
ultimately practical either).  And I also found myself wanting features 
like the assert reinterpretation, which I lost in doctests.

setup_module turned out to be quite useful; I added this to my conftest, 
and do a "from conftest import setup_module" in my module:

def setup_module(module):
     app = TestApp(server.make_app(CONFIG.current_conf()),
                   CONFIG.current_conf())
     module.app = app
     module.CONFIG = CONFIG
     fixture.reset_state()


I think it's likely that other boilerplate stuff will go in there in the 
future.  I'd still like doctests to work nicely, but it becomes less 
important to me.

Anyway, no requests here, just thought I'd share my current and always 
changing thoughts on the matter.

-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org



More information about the Pytest-dev mailing list