-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
Description
If a test gets skipped in SetupTest() in a suite that implements WithStats, the suite will panic on shutdown.
Step To Reproduce
package main
import (
"testing"
"github.com/stretchr/testify/suite"
)
type mySuite struct {
suite.Suite
}
func (s *mySuite) SetupTest() {
s.T().Skip("Just because!")
}
func (s *mySuite) HandleStats(_ string, _ *suite.SuiteInformation) {}
func (s *mySuite) TestSomething() {
panic("Should not get here.")
}
func TestAll(t *testing.T) {
suite.Run(t, &mySuite{})
}
Expected behavior
It shouldn’t panic. It should probably just skip that test.
Actual behavior
=== RUN TestAll
=== RUN TestAll/TestSomething
main_test.go:14: Just because!
panic.go:262: test panicked: runtime error: invalid memory address or nil pointer dereference
goroutine 22 [running]:
runtime/debug.Stack()
/Users/felipe/.local/share/mise/installs/go/1.23.7/src/runtime/debug/stack.go:26 +0x64
github.com/stretchr/testify/suite.failOnPanic(0x140000b9380, {0x1024861c0, 0x102744ee0})
/Users/felipe/go/src/github.com/10gen/mongosync/vendor/github.com/stretchr/testify/suite/suite.go:89 +0x38
github.com/stretchr/testify/suite.recoverAndFailOnPanic(0x140000b9380)
/Users/felipe/go/src/github.com/10gen/mongosync/vendor/github.com/stretchr/testify/suite/suite.go:83 +0x40
panic({0x1024861c0?, 0x102744ee0?})
/Users/felipe/.local/share/mise/installs/go/1.23.7/src/runtime/panic.go:791 +0x124
github.com/stretchr/testify/suite.SuiteInformation.end(...)
/Users/felipe/go/src/github.com/10gen/mongosync/vendor/github.com/stretchr/testify/suite/stats.go:34