Skip to content

Fix a few cases for how exceptions are passed to AfterX hooks#5240

Merged
stevenaw merged 5 commits into
mainfrom
5237-5238-hook-exception-bugfixes
Apr 24, 2026
Merged

Fix a few cases for how exceptions are passed to AfterX hooks#5240
stevenaw merged 5 commits into
mainfrom
5237-5238-hook-exception-bugfixes

Conversation

@stevenaw
Copy link
Copy Markdown
Member

@stevenaw stevenaw commented Apr 23, 2026

Fixes #5237 (Assert.Pass() shouldnt populate Exception property)
Fixes #5238 (Unwrap the exception before populating the hook data property)

@stevenaw stevenaw force-pushed the 5237-5238-hook-exception-bugfixes branch from c0ad7ce to d7c0de2 Compare April 23, 2026 19:21
@stevenaw stevenaw force-pushed the 5237-5238-hook-exception-bugfixes branch from d7c0de2 to 41598d6 Compare April 23, 2026 19:22
@stevenaw
Copy link
Copy Markdown
Member Author

I've added these linked issues to the 4.6 milestone. There's just a few additional test cases I'll need to cover and then this will be ready for review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts how exceptions are surfaced to execution “AfterX” hooks so that hooks receive the underlying exception (not wrapper exceptions) and do not treat Assert.Pass()’s SuccessException as an error.

Changes:

  • Normalize exceptions passed into After* execution hooks by unwrapping wrapper exceptions and filtering out SuccessException.
  • Add test fixtures and assertions covering exception propagation for AfterTest, AfterEverySetUp/TearDown, and test-action hooks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
src/NUnitFramework/framework/Internal/ExecutionHooks/ExecutionHooks.cs Unwraps exceptions and suppresses SuccessException before passing to After* hook handlers.
src/NUnitFramework/testdata/ExecutionHooks/CombinedHookTestFixtures.cs Adds new hook-enabled fixtures/attributes used by tests to capture exceptions from hooks.
src/NUnitFramework/tests/ExecutionHooks/ExceptionHandling/TestThrowsExceptionHooksProceedsToExecuteTests.cs Adds new unit tests asserting correct exception values (and absence) in After* hooks.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@stevenaw stevenaw marked this pull request as ready for review April 24, 2026 13:03
@stevenaw
Copy link
Copy Markdown
Member Author

This is now ready for review

@stevenaw stevenaw mentioned this pull request Apr 24, 2026
Copy link
Copy Markdown
Member

@OsirisTerje OsirisTerje left a comment

Choose a reason for hiding this comment

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

LGTM

@stevenaw
Copy link
Copy Markdown
Member Author

Thanks @OsirisTerje

@stevenaw stevenaw merged commit 3000dc4 into main Apr 24, 2026
9 checks passed
@stevenaw stevenaw deleted the 5237-5238-hook-exception-bugfixes branch April 24, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants