sys.excepthook is not called

Issue #535 resolved
Andrew Hoos
created an issue

This file does not call the handle_exception function when it is run through coverage, but it does when called through python. The global exception provides significant functionality that would be great to test. But I can't test with coverage because it disables the exception handler which changes the results of the test in question.

import sys

def handle_exception(exc_type, exc_value, exc_traceback):  # pragma: no cover
    print('exception')

sys.excepthandler = handle_exception

raise RuntimeError('Raised')

Comments (8)

  1. Florian Bruhin

    This doesn't call handle_exception with either python or coverage for me, but I can reproduce the issue you describe when using sys.excepthook instead (which I assume is just a typo?).

    FWIW --timid (which uses the slower python tracer) doesn't change anything.

  2. Ned Batchelder repo owner

    Hmm, interesting. Technically, coverage.py doesn't disable the exception handler, but it does catch all the exceptions at the top of the stack. I guess coverage/execfile.py needs to invoke the excepthook explicitly?

  3. Log in to comment