Ensure files are closed in the tests