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
When having tests with subtests, the calling of the
s.T().Name()in theTearDownSubTestwill return the parent test name and not the subtest that has been executedHaving this test executed will print the correct sub-test names:
Output:
And I would expect that in the
TearDownSubTest, thes.T().Name()should be consistent with these names. However, it always refers to the parent test name, i.e.,TestingSuite/TestWithSubtestsfor theTestingSuite/TestWithSubtests/my_subtest, andTestingSuite/TestWithSubtests/my_subtestfor theTestingSuite/TestWithSubtests/my_subtest/my_sub_subtest.Output:
Environment:
Go 1.19
Testify 1.8.4