to Doctest as SystemExit is to Python

p.lavarre at p.lavarre at
Fri Nov 10 06:25:24 CET 2006

> From: ...
> Regression testing is best confined to dedicated objects or files ...

Can I somehow tell doctest that it's time to quit?

I ask because not all doctest examples are created equal.  Some
failures are catastrophic, making all subsequent failures at least
uninteresting, and maybe painfully slow.  Other failures are
negligible, making the print of any subsequent failure valuable.

So sys.exit() doesn't do what I mean: it raises SystemExit, but doctest
redefines the SystemExit exception to mean print a traceback, rather
than meaning to exit quietly after a noisily catastrophic failure,
exiting almost as if the doctest had passed.

And doctest.REPORT_ONLY_FIRST_FAILURE doesn't do what I mean: it prints
only the first failure, always, never the valuable subsequent failures.

Can doctest somehow be persuaded to do the right thing?  That is, to
exit after a catastrophic failure, but not after a negligible failure,
and not after an independent failure?

In the last Python I shipped, to get the effect of exit after
catastrophe, I actually faked a run of doctest:

print 'Expected:'
print "    '...'"
print 'Got:'
print "    " + repr(result)
print '***Test Failed***'

Surely that's wrong?  Somehow not idiomatic Python?

Surely I can somehow tell doctest that my code has just realised,
sorry, it is time to quit?

Thanks in advance, Pat LaVarre

More information about the Python-list mailing list