summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorSamet YASLAN <sametyaslan@gmail.com>2023-06-11 18:51:21 (GMT)
committerGitHub <noreply@github.com>2023-06-11 18:51:21 (GMT)
commit3f7c0810f6158a7ff37be432f8d7f9511427489f (patch)
tree2d7aa6981b6b921ac8da80696cc568bf4e712c70 /Lib/unittest/mock.py
parent18d16e93b6d4b7b10c5145890daa92b760fe962a (diff)
downloadcpython-3f7c0810f6158a7ff37be432f8d7f9511427489f.zip
cpython-3f7c0810f6158a7ff37be432f8d7f9511427489f.tar.gz
cpython-3f7c0810f6158a7ff37be432f8d7f9511427489f.tar.bz2
bpo-44185: Added close() to mock_open __exit__ (#26902)
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 4ca7062..f10f9b0 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2941,6 +2941,9 @@ def mock_open(mock=None, read_data=''):
return handle.readline.return_value
return next(_state[0])
+ def _exit_side_effect(exctype, excinst, exctb):
+ handle.close()
+
global file_spec
if file_spec is None:
import _io
@@ -2967,6 +2970,7 @@ def mock_open(mock=None, read_data=''):
handle.readlines.side_effect = _readlines_side_effect
handle.__iter__.side_effect = _iter_side_effect
handle.__next__.side_effect = _next_side_effect
+ handle.__exit__.side_effect = _exit_side_effect
def reset_data(*args, **kwargs):
_state[0] = _to_stream(read_data)