Radar · Go · Archive · Week 35 · Aug 25 – 31, 2025
testing: use $GOTMPDIR for temporary files when set
Worth knowingstdlib
- What changed
- The testing package will now use the $GOTMPDIR environment variable for temporary files when it is set.
- Production impact
- The source does not say.
- Try it
- Run a test with
export GOTMPDIR=/tmp/go-testand observe thatt.TempDir()creates files in that directory. - Source
- github.com/golang/go/issues/61585
Understand it, then run it
The testing package creates temporary files when a test needs them. Before the change, it always used the system’s temporary directory, the one returned by os.TempDir(). Now, if the environment variable GOTMPDIR is set, the testing package will use that directory instead. This lets developers run tests on machines where the normal temp directory is locked or otherwise unsuitable, without changing the rest of the system.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed