Skip to content

Proposal: add context.Context objects to testing.T EDIT: and testing.M #18182

Closed
@Lucretiel

Description

@Lucretiel

Proposal: add a test-local Context object to testing.T objects. The object would be accessible like this:

func TestSomething(t *testing.T) {
    ctx = t.Context()
    ...
}

It would be cancelled at the end of the test. This would allow tests involving network calls, parallel goroutines, or other blocking code to use the context to cancel all the background stuff in the event the test fails an assertion early with FailNow or something similar.

It should be a fairly straightforward feature, so if there's interest I can create a Pull Request when I have time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions