Properly save environment variables during tests