-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
mock_open file handle __exit__ does not call close #88351
Comments
A common testing scenario is assuring that opened files are closed. Since unittest.mock.mock_open() can be used as a context manager, it would be reasonable to expect its __exit__ to invoke close so that one can easily assert that the file was closed, regardless of if the file was opened with a plain call to open or with a context manager. |
@MaxwellDupre / @samety - following up here as it's the issue that resulted in #26902... (/cc @tirkarthi ) What's your actual need for recording the
While I don't see anything bad about the PR to fix this, I'm reticent to merge without a really good reason as it may result in many test expectations having to be updated. |
We'd like this change to uphold a good test principle of testing behaviour, not implementation. I.e. we want to test that the code closes the file, not how it closes it. So changing the code from explicitly calling |
Okay, let's land #26902 :-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: