Skip to content

Test name refers to parent test name in TearDownSubTest #1465

@SeriyBg

Description

@SeriyBg

When having tests with subtests, the calling of the s.T().Name() in the TearDownSubTest will return the parent test name and not the subtest that has been executed
Having this test executed will print the correct sub-test names:

func (s *TestingSuite) TestWithSubtests() {
  s.Run("my subtest", func() {
    println("my subtest -> " + s.T().Name())
    s.Run("my sub subtest", func() {
      println("my sub subtest -> " + s.T().Name())
    })
  })
}

Output:

=== RUN   TestingSuite/TestWithSubtests
=== RUN   TestingSuite/TestWithSubtests/my_subtest
my subtest -> TestSuite/TestHazelcastExternalSmartClientLoadBalancer/my_subtest
=== RUN   TestingSuite/TestWithSubtests/my_subtest/my_sub_subtest
my sub subtest -> TestSuite/TestHazelcastExternalSmartClientLoadBalancer/my_subtest/my_sub_subtest

And I would expect that in the TearDownSubTest, the s.T().Name() should be consistent with these names. However, it always refers to the parent test name, i.e., TestingSuite/TestWithSubtests for the TestingSuite/TestWithSubtests/my_subtest, and TestingSuite/TestWithSubtests/my_subtest for the TestingSuite/TestWithSubtests/my_subtest/my_sub_subtest.

func (s *TestingSuite) TearDownSubTest() {
  println("TearDownSubTest -> " + s.T().Name())
}

Output:

TearDownSubTest -> TestSuite/TestHazelcastExternalSmartClientLoadBalancer/my_subtest
TearDownSubTest -> TestSuite/TestHazelcastExternalSmartClientLoadBalancer

Environment:
Go 1.19
Testify 1.8.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpkg-suiteChange related to package testify/suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions