to Doctest as SystemExit is to Python

pelavarre at gmail.com pelavarre at gmail.com
Thu Dec 13 09:32:56 EST 2007


> Sent: 2006-11-09; To: comp.lang.python
>
> Can doctest ... be persuaded to exit after a catastroph[e]...?
> ...
> sys.exit() doesn't do what I mean:
> it raises SystemExit ... [and doesn't exit]
> ...
> doctest.REPORT_ONLY_FIRST_FAILURE doesn't do what I mean
> [it filters stdout but doesn't exit]

Yes doctest can be asked to HALT_AT_NTH_FAILURE, including
HALT_AT_FIRST_FAILURE.

Merely (1) construct an object to replace stdout, so that (2) you can
redefine the stdout.write calls of doctest, so that (3) you can filter
the bytes written there, so that (4) you can raise KeyboardInterrupt,
so that (5) you can exit when you please.

Not a documented feature. Mostly works all the same.

A working example appeared at http://wiki.python.org/moin/doctest on
2007-11-12.

-- Pat LaVarre




More information about the Python-list mailing list