This is a follow up issue for https://github.com/golang/go/issues/27927#issuecomment-566686467, which discussed having an alternative mechanism to run tests from within TestMain. The proposal was the following:

func TestMain(m *testing.M) {
    setupAll()
    code := m.RunEach(func(t *testing.T) {
        setup(t)
        t.Run()
        teardown(t)
    })
    teardownAll()
    os.Exit(code)
}

Basically, testing.M should provide a way to iterate through the tests and allow code to be executed before and after each.

Originally posted by @mgwidmann in https://github.com/golang/go/issues/27927#issuecomment-566686467

Comment From: gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: seankhliao

Duplicate of #53701