Mere Code

Diverse Topics of General Interest to the Practicing Programmer

doctest really isn't very good

I just got sick of trying to decode obtuse doctest diff errors when using NORMALIZE_WHITESPACE and ELLIPSIS options. Although doctest gives you hooks to do something about this, it’s really hard to actually write the logic.

See, NORMALIZE_WHITESPACE also normalizes line breaks, and ‘…’ can match across multiple lines. That means that you can’t take a line-based approach, which makes it really hard to clean up a diff. Anyway, here’s my attempt:

It’s a pain, because both of them would be very useful without their line-spanning behaviour. I guess without the line-spanning behaviour of ‘…’ there’d be no way to indicate multiple lines of crap in output.

My suggestion in the mean time? Don’t use doctest.


jml on 2011-09-14 10:05
I think line-based checking could be a good start.
gz on 2011-09-14 01:19
I'm not a fan of doctest.OutputChecker either. I don't find spelling assertions with ellipses rather than regular expressions much of an improvement, and the mismatch output nearly always confuses me. There must be some better pattern for doing checks on (potentially very) large text blocks that's easy to write and actually produces good errors. I've not managed to come up with one though…