Skip to content

skip in SetupTest() with HandleStats() causes panic #1722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
FGasper opened this issue Apr 2, 2025 · 0 comments · May be fixed by #1723
Open

skip in SetupTest() with HandleStats() causes panic #1722

FGasper opened this issue Apr 2, 2025 · 0 comments · May be fixed by #1723
Labels

Comments

@FGasper
Copy link

FGasper commented Apr 2, 2025

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
@FGasper FGasper added the bug label Apr 2, 2025
FGasper added a commit to FGasper/testify that referenced this issue Apr 2, 2025
@FGasper FGasper linked a pull request Apr 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant