Skip to content

proposal: testing: add more support to automatically cleanup temporary resources or temporary changes to the global environment #45403

@perillo

Description

@perillo

In go 1.15, the testing package supports the T.TempDir function.
Currently the method is not used in the tests of the go distribution, but os.MkdirTemp is used 164 times.

Here is a list of additional API to manage temporary resources or temporary changes to the global environment in tests:

  • T.ChTempDir
    Currently all: tests that change the working directory should use defer to restore it #45182 has introduced the chdir function, but there are several tests that use it.
    os.Chdir is used 53 times (including in chdir and chtmpdir), the new chdir is used 8 times and the old chtmpdir is used 22 times.

  • T.TempFile.
    Currently os.CreateTemp is used 33 times in tests.

  • T.SetTempEnv
    Currently os.Setenv is used 108 times.

The usage number has been computed with a simple: grep -F "fname(" **/*_test.go | wc -l

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Proposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions