doctest and an obvious mistake
Jul. 10th, 2008 08:32 pmAs I was running through and tidying up the comments I had a brainwave. Why not merge the functionality tests into the comments and use doctest to run a complete regression on the module? So I did. And everything went swimmingly, right up until I added a set of tests for a modified command line parser object. The offending test went something like this:
>>> p = MyParser()
>>> p.add_option("-a")
<MyOption at 0x...: -a>
But every time I ran the test I got the following failure:
Expected:
<MyOption at 0x...: -a>
Got:
<MyOption at 0x4033a20c: -a>
Which would have been fine, except that, as per the manual, I'd specifically put in a set of ellipses to deal with the fact that the address was likely to differ. But what, it transpires, I'd missed was that the doctest needs to know to enable ellipses, either on a per test basis with a "#doctest: +ELLIPSIS" pragma directive tagged on to the specific test or by passing the correct flag to the appropriate doctest function, e.g.
from doctest import testmod, ELLIPSES
testmod(optionflags=ELLIPSES)
Rather embarrassingly, it took me almost an hour to work out what I was doing wrong...