mirror of https://github.com/stretchr/testify.git
Move teardown defers to before setup
parent
f43aa3c488
commit
f238e4b70a
|
@ -111,14 +111,6 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
suiteName := methodFinder.Elem().Name()
|
suiteName := methodFinder.Elem().Name()
|
||||||
|
|
||||||
if !suiteSetupDone {
|
if !suiteSetupDone {
|
||||||
if stats != nil {
|
|
||||||
stats.Start = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
|
||||||
setupAllSuite.SetupSuite()
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
||||||
testsSync.Wait()
|
testsSync.Wait()
|
||||||
|
@ -130,6 +122,9 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
suiteWithStats.HandleStats(suiteName, stats)
|
suiteWithStats.HandleStats(suiteName, stats)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
||||||
|
setupAllSuite.SetupSuite()
|
||||||
|
}
|
||||||
suiteSetupDone = true
|
suiteSetupDone = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,19 +135,6 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
parentT := suite.T()
|
parentT := suite.T()
|
||||||
suite.SetT(t)
|
suite.SetT(t)
|
||||||
defer failOnPanic(t)
|
defer failOnPanic(t)
|
||||||
|
|
||||||
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
|
||||||
setupTestSuite.SetupTest()
|
|
||||||
}
|
|
||||||
|
|
||||||
if beforeTestSuite, ok := suite.(BeforeTest); ok {
|
|
||||||
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if stats != nil {
|
|
||||||
stats.start(method.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if stats != nil {
|
if stats != nil {
|
||||||
passed := !t.Failed()
|
passed := !t.Failed()
|
||||||
|
@ -169,6 +151,13 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
|
|
||||||
suite.SetT(parentT)
|
suite.SetT(parentT)
|
||||||
}()
|
}()
|
||||||
|
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
||||||
|
setupTestSuite.SetupTest()
|
||||||
|
}
|
||||||
|
if beforeTestSuite, ok := suite.(BeforeTest); ok {
|
||||||
|
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
|
||||||
|
}
|
||||||
|
|
||||||
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue