From a4a54a4597c8c0ea19314400cfd9cd6f8e5afe59 Mon Sep 17 00:00:00 2001 From: Linus Barth Date: Wed, 18 Oct 2023 03:22:36 +0200 Subject: [PATCH] fix: panic behavior for subtests This fix adds panic handling for subtests which will achieve: - subtests will fail for the correct test context when panicking - the test execution is not stopped; the next subtest will be executed --- suite/suite.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/suite/suite.go b/suite/suite.go index cca7533..f3aa9a1 100644 --- a/suite/suite.go +++ b/suite/suite.go @@ -98,9 +98,10 @@ func (suite *Suite) Run(name string, subtest func()) bool { return oldT.Run(name, func(t *testing.T) { suite.SetT(t) - defer suite.SetT(oldT) + defer recoverAndFailOnPanic(t) + if setupSubTest, ok := suite.s.(SetupSubTest); ok { setupSubTest.SetupSubTest() }