Don't setup suite if no methods satisfy filter

When suite setup is long, the necessity to wait for all suite setups for testing one single method bothers a lot. Here's a little fix of that behavior.
pull/731/head
Tigran Saluev 2019-02-08 22:14:16 +03:00 committed by George Lesica
parent 363ebb24d0
commit 3efd733edb
1 changed files with 41 additions and 36 deletions

View File

@ -82,14 +82,7 @@ func Run(t *testing.T, suite TestingSuite) {
suite.SetT(t)
defer failOnPanic(t)
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
setupAllSuite.SetupSuite()
}
defer func() {
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
tearDownAllSuite.TearDownSuite()
}
}()
setupDone := false
methodFinder := reflect.TypeOf(suite)
tests := []testing.InternalTest{}
@ -100,7 +93,20 @@ func Run(t *testing.T, suite TestingSuite) {
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
os.Exit(1)
}
if ok {
if !ok {
continue
}
if !setupDone {
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
setupAllSuite.SetupSuite()
}
defer func() {
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
tearDownAllSuite.TearDownSuite()
}
}()
setupDone = true
}
test := testing.InternalTest{
Name: method.Name,
F: func(t *testing.T) {
@ -128,7 +134,6 @@ func Run(t *testing.T, suite TestingSuite) {
}
tests = append(tests, test)
}
}
runTests(t, tests)
}