Skip to content

recover in subtests #764

@xwjdsh

Description

@xwjdsh
package main

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/suite"
)

type Suite struct {
	suite.Suite
}

func TestXX(t *testing.T) {
	suite.Run(t, new(Suite))
}

func (s *Suite) SetupSuite() {
	fmt.Println("In SetupSuite")
}

func (s *Suite) TearDownSuite() {
	fmt.Println("In TearDownSuite")
}

func (s *Suite) TestXX_YY() {
	s.Run("test xx yy", func() {
		panic("test")
	})
}

For the above snippet, it panics in subtest and does not enter the TearDownSuite, should we add failOnPanic in the subtests? like this:

func (suite *Suite) Run(name string, subtest func()) bool {
	oldT := suite.T()
	defer suite.SetT(oldT)
	return oldT.Run(name, func(t *testing.T) {
+		defer failOnPanic(t)
		suite.SetT(t)
		subtest()
	})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions