Skip to content

Simplify config tests by using T.Setenv, T.TempDir#2014

Merged
jackc merged 1 commit intojackc:masterfrom
alexandear:test/simplify-config-tests
May 15, 2024
Merged

Simplify config tests by using T.Setenv, T.TempDir#2014
jackc merged 1 commit intojackc:masterfrom
alexandear:test/simplify-config-tests

Conversation

@alexandear
Copy link
Contributor

The PR simplifies config tests by refactoring code and without harming readability:

  • Use T.Setenv instead of os.Setenv. Because T.Setenv calls os.Setenv(key, value) and uses T.Cleanup to restore the environment variable to its original value after the test. So, the test doesn't need to restore the environment by itself.
  • Use T.TempDir instead of os.CreateTemp to create a temporary file. TempDir returns a temporary directory which is automatically removed when the test and all its subtests complete.

@jackc jackc merged commit 0080acf into jackc:master May 15, 2024
@jackc
Copy link
Owner

jackc commented May 15, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants