From b808998ec312f9e4abfbc8d333f9d9d6f82fafec Mon Sep 17 00:00:00 2001 From: renzo Date: Mon, 16 Jun 2025 19:39:08 +0200 Subject: [PATCH 1/2] suite.Run: simplify running of Setup/TeardownSuite --- suite/suite.go | 47 +++++++++++++++++------------------- suite/testify.code-workspace | 10 ++++++++ 2 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 suite/testify.code-workspace diff --git a/suite/suite.go b/suite/suite.go index 7c79250bb..a7ceba731 100644 --- a/suite/suite.go +++ b/suite/suite.go @@ -128,8 +128,6 @@ func Run(t *testing.T, suite TestingSuite) { suite.SetT(t) suite.SetS(suite) - var suiteSetupDone bool - var stats *SuiteInformation if _, ok := suite.(WithStats); ok { stats = newSuiteInformation() @@ -152,18 +150,6 @@ func Run(t *testing.T, suite TestingSuite) { continue } - if !suiteSetupDone { - if stats != nil { - stats.Start = time.Now() - } - - if setupAllSuite, ok := suite.(SetupAllSuite); ok { - setupAllSuite.SetupSuite() - } - - suiteSetupDone = true - } - test := test{ name: method.Name, run: func(t *testing.T) { @@ -208,19 +194,30 @@ func Run(t *testing.T, suite TestingSuite) { } tests = append(tests, test) } - if suiteSetupDone { - defer func() { - if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { - tearDownAllSuite.TearDownSuite() - } - - if suiteWithStats, measureStats := suite.(WithStats); measureStats { - stats.End = time.Now() - suiteWithStats.HandleStats(suiteName, stats) - } - }() + + if len(tests) == 0 { + return + } + + if stats != nil { + stats.Start = time.Now() + } + + if setupAllSuite, ok := suite.(SetupAllSuite); ok { + setupAllSuite.SetupSuite() } + defer func() { + if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { + tearDownAllSuite.TearDownSuite() + } + + if suiteWithStats, measureStats := suite.(WithStats); measureStats { + stats.End = time.Now() + suiteWithStats.HandleStats(suiteName, stats) + } + }() + runTests(t, tests) } diff --git a/suite/testify.code-workspace b/suite/testify.code-workspace new file mode 100644 index 000000000..682df5e52 --- /dev/null +++ b/suite/testify.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": ".." + }, + { + "path": "../../testify" + } + ] +} \ No newline at end of file From cda19a717a4cd025015833ca7b56608e4e41b588 Mon Sep 17 00:00:00 2001 From: renzoarreaza Date: Thu, 19 Jun 2025 10:06:59 +0200 Subject: [PATCH 2/2] Delete suite/testify.code-workspace --- suite/testify.code-workspace | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 suite/testify.code-workspace diff --git a/suite/testify.code-workspace b/suite/testify.code-workspace deleted file mode 100644 index 682df5e52..000000000 --- a/suite/testify.code-workspace +++ /dev/null @@ -1,10 +0,0 @@ -{ - "folders": [ - { - "path": ".." - }, - { - "path": "../../testify" - } - ] -} \ No newline at end of file