New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci(package): NamedTemporaryFile Being Opened Twice #2567
Conversation
@@ -131,6 +131,10 @@ def test_package_template_with_image_function_in_nested_application(self, templa | |||
# when image function is not in main template, erc_repo_name does not show up in stdout | |||
# here we download the nested application template file and verify its content | |||
with tempfile.NamedTemporaryFile() as packaged_file, tempfile.TemporaryFile() as packaged_nested_file: | |||
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile | |||
# Closes the NamedTemporaryFile as on Windows NT or later, NamedTemporaryFile cannot be opened twice. | |||
packaged_file.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use TemporaryFile()
for package_file
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TemporaryFile does not guarantee the file is visible in the file system on Unix. We need to read the file later using packaged_file.name in order to validate the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a visible name for package_file
in the file system, which is used for output_template_file
in the command.
TemporaryFile()
does not guarantee a visible name in the file system.
We don't need the file to actually exist though. Since the command will create the file again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Which issue(s) does this change fix?
Why is this change necessary?
In Windows NT or later, NamedTemporaryFile cannot be opened twice.
https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
How does it address the issue?
What side effects does this change have?
Checklist
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.