-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Validate suite method signatures and continue execution for valid tests #1665
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error shows up when you run a valid test. Previously there is no panic in this scenario.
eg:
package kata_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type ExampleTestSuite struct {
suite.Suite
VariableThatShouldStartAtFive int
}
func (suite *ExampleTestSuite) SetupTest() {
suite.VariableThatShouldStartAtFive = 5
}
func (suite *ExampleTestSuite) TestExample() {
assert.Equal(suite.T(), 6, suite.VariableThatShouldStartAtFive)
}
func (suite *ExampleTestSuite) TestSomething(a any) {
suite.Equal(1, a)
}
func TestExampleTestSuite(t *testing.T) {
suite.Run(t, new(ExampleTestSuite))
}
% go test -run=TestExampleTestSuite/TestExample
--- FAIL: TestExampleTestSuite (0.00s)
suite.go:153: testify: suite method 'TestSomething' has 1 input arguments and 0 return values. It should have none.
FAIL
exit status 1
FAIL github.com/brackendawson/kata 0.280s
@brackendawson Thank you for pointing that out! I understand the concern. Since The suite considers all its methods, and I considered using To address this, I updated the approach to log a warning message directly and skip invalid methods without using
Thank you for your feedback, please let me know if this approach aligns with the intended behavior or if there are further adjustments you’d like to see! |
Summary
This PR improves method signature validation in Testify's suite execution by ensuring that invalid methods are logged, and valid methods continue to execute.
Changes
t.Fatalf
witht.Errorf
to report invalid method signatures while allowing the test suite to continue executing valid methods.Motivation
Related issues