Skip to content

Conversation

eltimen
Copy link

@eltimen eltimen commented Aug 12, 2022

Fixes #9036
The behavior in the issue is observed because pytest.warn don't capture warnings when an exception is raised inside a with block due to the condition in WarningsChecker.__exit__.
It looks like removing this condition should fix this bug, Or is it needed to cover some case?

pytest.warn and similar functions should capture warnings when an exception is raised inside a with block
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

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

This is a breaking change to intended behaviour,

Else the other exception gets hidden

@eltimen
Copy link
Author

eltimen commented Aug 12, 2022

Hello @RonnyPfannschmidt. Could you please clarify what you mean by "other exception gets hidden" (with a minimal example, if possible)?

@RonnyPfannschmidt
Copy link
Member

If the code that should warn
Raises any exception, the new exception supersedes it

@eltimen eltimen closed this Aug 19, 2022
@Zac-HD
Copy link
Member

Zac-HD commented Jun 19, 2023

@RonnyPfannschmidt I think we should replace the existing error with a Failed (because no matching warning); otherwise this nasty issue is just unsolvable. Fortunately exception chaining will ensure that users can see the superseded exception too.

Can't re-open this when the upstream repo has been deleted, but I'll open a new one soon.

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.

pytest.warns and pytest.raises ordering issue

3 participants