I would prefer mocking file with a file-lock object (e.g. StringIO), but I see the point to doing it this way so up to you.