Skip to content

bpo-33753: Refactor creating temporary files in test_fileinput.#7377

Merged
serhiy-storchaka merged 2 commits into
python:masterfrom
serhiy-storchaka:test_fileinput-writeTmp
Jun 5, 2018
Merged

bpo-33753: Refactor creating temporary files in test_fileinput.#7377
serhiy-storchaka merged 2 commits into
python:masterfrom
serhiy-storchaka:test_fileinput-writeTmp

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jun 4, 2018

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. addCleanup() is a good solution.

I asked a question, but it shouldn't be a blocker issue.

Comment thread Lib/test/test_fileinput.py Outdated
count = 0
def writeTmp(self, content, *, mode='w'): # opening in text mode is the default
self.count += 1
name = TESTFN + str(self.count)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using tempfile.mktemp()? tempfile uses a temporary directory which is cleared sometimes at system boot. It prevents leaking temporary files if Python does crash.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I proposed mktemp() but mkstemp() may be even better.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

mktemp() is half-deprecated. THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED.

@serhiy-storchaka serhiy-storchaka merged commit 5f48e26 into python:master Jun 5, 2018
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the test_fileinput-writeTmp branch June 5, 2018 09:08
@bedevere-bot

Copy link
Copy Markdown

GH-7417 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 5, 2018
…onGH-7377)

(cherry picked from commit 5f48e26)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5f48e2644dcfb47f0bbc0fcdc2b103a19bdec288 3.6

miss-islington added a commit that referenced this pull request Jun 5, 2018
)

(cherry picked from commit 5f48e26)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jun 5, 2018
…pythonGH-7377).

(cherry picked from commit 5f48e26)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-7431 is a backport of this pull request to the 3.6 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants