Skip to content

suite: prevent panic when SetupTest skips with HandleStats#1877

Merged
dolmen merged 1 commit into
stretchr:masterfrom
blackwell-systems:fix/suite-skip-stats-panic
May 11, 2026
Merged

suite: prevent panic when SetupTest skips with HandleStats#1877
dolmen merged 1 commit into
stretchr:masterfrom
blackwell-systems:fix/suite-skip-stats-panic

Conversation

@blackwell-systems
Copy link
Copy Markdown
Contributor

@blackwell-systems blackwell-systems commented Apr 27, 2026

Motivation

When a suite implements HandleStats (the WithStats interface) and SetupTest() calls t.Skip(), the suite panics with a nil pointer dereference. This is a bug, not expected behavior.

The bug

stats.start() was registered after SetupTest() in the test runner. When SetupTest() calls t.Skip(), Go's runtime.Goexit() fires, skipping stats.start() entirely. The deferred stats.end() then accesses s.TestStats[testName] which is nil because start() never created the map entry.

The fix

Move stats.start() before SetupTest() so the TestStats entry always exists when end() runs, regardless of whether setup skips, fails, or panics. This also makes timing more accurate since setup duration is now included.

One line moved, one test added. All 8 packages pass.

Fixes #1722

@dolmen dolmen changed the title fix(suite): prevent panic when SetupTest skips with HandleStats suite: prevent panic when SetupTest skips with HandleStats May 7, 2026
@dolmen dolmen added the pkg-suite Change related to package testify/suite label May 7, 2026
@dolmen dolmen force-pushed the fix/suite-skip-stats-panic branch from df6e494 to 52a4271 Compare May 7, 2026 13:59
@dolmen
Copy link
Copy Markdown
Collaborator

dolmen commented May 7, 2026

@blackwell-systems Please fix the commit message to replace "fix(suite): prevent panic" with "suite: fix panic"

@dolmen dolmen force-pushed the fix/suite-skip-stats-panic branch from 636bacf to fdc6894 Compare May 11, 2026 15:27
@dolmen dolmen merged commit 37a3cb7 into stretchr:master May 11, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg-suite Change related to package testify/suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

suite: skip in SetupTest() with HandleStats() causes panic

2 participants