Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.excepthook is not called #535

Closed
nedbat opened this issue Nov 29, 2016 · 8 comments
Closed

sys.excepthook is not called #535

nedbat opened this issue Nov 29, 2016 · 8 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Nov 29, 2016

Originally reported by Andrew Hoos (Bitbucket: andrewhoos, GitHub: andrewhoos)


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.

#!python

import sys

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

sys.excepthandler = handle_exception

raise RuntimeError('Raised')

@nedbat
Copy link
Owner Author

nedbat commented Nov 29, 2016

Original comment by Florian Bruhin (Bitbucket: The-Compiler, GitHub: The-Compiler)


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.

@nedbat
Copy link
Owner Author

nedbat commented Nov 29, 2016

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?

@nedbat
Copy link
Owner Author

nedbat commented Dec 12, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


The exception is caught and the traceback printed in cmdline.py. Although sys.excepthook is properly set, it does not get a chance to run.

@nedbat
Copy link
Owner Author

nedbat commented Dec 12, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


Tentative fix at https://bitbucket.org/ned/coveragepy/pull-requests/96/honor-sysexcepthook/diff

@nedbat
Copy link
Owner Author

nedbat commented Dec 12, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


For the record, another pull request at https://bitbucket.org/ned/coveragepy/pull-requests/93/explicitely-call-sysexcepthook/diff which I missed tries patching execfile instead

@nedbat
Copy link
Owner Author

nedbat commented Dec 18, 2016

Original comment by Loic Dachary (Bitbucket: dachary, GitHub: dachary)


I declined my pull request because I think Andrew Hoos pull request is a better fix.

@nedbat
Copy link
Owner Author

nedbat commented Dec 26, 2016

Fixed by pull request 93: https://bitbucket.org/ned/coveragepy/pull-requests/93/explicitely-call-sysexcepthook/diff

And by the commits following, up to 60e9b1b2f820 (bb).

@nedbat
Copy link
Owner Author

nedbat commented Dec 27, 2016

This fix was released as part of Coverage.py 4.3.

@nedbat nedbat closed this as completed Dec 27, 2016
@nedbat nedbat added major bug Something isn't working labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant