FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-150484: Add test for mock_open __exit__ with contextlib.ExitStack by factnn · Pull Request #150521 · python/cpython · GitHub

Repository navigation

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 9 additions & 0 deletions Lib/test/test_unittest/testmock/testmock.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,15 @@ def test_mock_open_after_eof(self):
self.assertEqual([], h.readlines())
self.assertEqual([], h.readlines())

def test_mock_open_exit_with_contextlib_exit_stack(self):
# gh-150484: mock_open's __exit__ should work when called from
# contextlib.ExitStack, which passes (exctype, excinst, exctb).
from contextlib import ExitStack
with mock.patch('builtins.open', mock.mock_open()) as m:
with ExitStack() as exit_stack:
with exit_stack.enter_context(open('/tmp/test.txt', 'w')):
pass

def test_mock_parents(self):
for Klass in Mock, MagicMock:
m = Klass()
Expand Down
Loading

Back | FazBrowse Home | New Git URL