Fix restoring original environment during unit testing