-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-33752: Fix a file leak in test_dbm. #7376
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
bpo-33752: Fix a file leak in test_dbm. #7376
Conversation
With addCleanup() f.close() was executed after tearDown().
Lib/test/test_dbm.py
Outdated
@@ -75,10 +75,9 @@ def test_anydbm_creation(self): | |||
def test_anydbm_creation_n_file_exists_with_invalid_contents(self): | |||
# create an empty file | |||
test.support.create_empty_file(_fname) | |||
|
|||
f = dbm.open(_fname, 'n') |
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.
Use maybe: try/finally, just in case.
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.
There are 11 other calls of close()
without try/finally. I had doubts about adding try/finally in all these cases. Maybe in a separate commit.
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.
Maybe you can use "with f:" if you don't want to use try/finally :-)
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.
It is not supported in 2.7. On other side, this PR will be not applied to 2.7, because test_dbm is rudimentary in 2.7.
@@ -75,10 +75,9 @@ def test_anydbm_creation(self): | |||
def test_anydbm_creation_n_file_exists_with_invalid_contents(self): | |||
# create an empty file | |||
test.support.create_empty_file(_fname) |
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.
Please keep the empty line. IMHO it helps for the readability.
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.
This test is short (just 4 lines), and no other test method contains an empty line inside. Having an empty line that splits this short test rather adds a false signal that attract an attention to an insignificant detail.
But if you still think that it is worth to restore an empty line, I'll do this.
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.
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
With addCleanup() f.close() was executed after tearDown(). (cherry picked from commit 6592d7f) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-7429 is a backport of this pull request to the 3.6 branch. |
With addCleanup() f.close() was executed after tearDown(). (cherry picked from commit 6592d7f) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-7430 is a backport of this pull request to the 3.7 branch. |
With addCleanup() f.close() was executed after tearDown(). (cherry picked from commit 6592d7f) Co-authored-by: Serhiy Storchaka <[email protected]>
With addCleanup() f.close() was executed after tearDown(). (cherry picked from commit 6592d7f) Co-authored-by: Serhiy Storchaka <[email protected]>
With addCleanup() f.close() was executed after tearDown().
https://bugs.python.org/issue33752