testing.T.Cleanup ensures the environment is restored after a test and any of its parallel sub-tests. It's possible that these can be simplified further to T.Setenv(key, ""), but I did not investigate.