Skip to content

proposal: testing: per-test setup and teardown support #68354

@PapaCharlie

Description

@PapaCharlie

This is a follow up issue for #27927 (comment), 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 #27927 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions