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

Test exception handling preserves the call stack. #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aebrahim
Copy link
Member

@aebrahim aebrahim commented Nov 3, 2023

This way, using a once decorator will not swallow all exception traces.

@aebrahim aebrahim changed the title Preserve stack Exception handling preserves the callers stack. Nov 3, 2023
@aebrahim aebrahim force-pushed the preserve_stack branch 3 times, most recently from dfba7db to 701383f Compare November 8, 2023 05:34
@aebrahim aebrahim changed the title Exception handling preserves the callers stack. Test exception handling preserves the call stack. Nov 8, 2023
This way, using a once decorator will not swallow all exception traces.
@aebrahim aebrahim marked this pull request as ready for review November 8, 2023 19:48
@aebrahim aebrahim requested a review from mattalbr January 9, 2024 17:32
Copy link
Collaborator

@mattalbr mattalbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like no code changes were needed, this just adds test coverage?

container.exception = exception
traceback_exception = traceback.TracebackException.from_exception(exception)
if not len(traceback_exception.stack):
test.fail("Exception stack not preserved. Did you use the raw assertRaises by mistake?")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there was a raw assertRaises, wouldn't we never get to this failure in the first place?

locations = [(frame.filename, frame.lineno) for frame in traceback_exception.stack]
line_number = line.line
error_message = [
f"Traceback for exception {repr(exception)} did not have frame on line {line_number}. Exception below\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit strange, can you explain what it's about?

@aebrahim
Copy link
Member Author

aebrahim commented Jan 9, 2024

Looks like no code changes were needed, this just adds test coverage?

Yup, exactly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants