mirror of
https://github.com/python/cpython.git
synced 2025-08-15 06:10:47 +00:00
[3.9] bpo-44566: resolve differences between asynccontextmanager and contextmanager (GH-27024). (#27269)
(cherry picked from commit 7f1c330da3
)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
parent
dae4928dd0
commit
1c5c9c89ff
4 changed files with 78 additions and 44 deletions
|
@ -125,19 +125,22 @@ class ContextManagerTestCase(unittest.TestCase):
|
|||
self.assertEqual(state, [1, 42, 999])
|
||||
|
||||
def test_contextmanager_except_stopiter(self):
|
||||
stop_exc = StopIteration('spam')
|
||||
@contextmanager
|
||||
def woohoo():
|
||||
yield
|
||||
try:
|
||||
with self.assertWarnsRegex(DeprecationWarning,
|
||||
"StopIteration"):
|
||||
with woohoo():
|
||||
raise stop_exc
|
||||
except Exception as ex:
|
||||
self.assertIs(ex, stop_exc)
|
||||
else:
|
||||
self.fail('StopIteration was suppressed')
|
||||
|
||||
class StopIterationSubclass(StopIteration):
|
||||
pass
|
||||
|
||||
for stop_exc in (StopIteration('spam'), StopIterationSubclass('spam')):
|
||||
with self.subTest(type=type(stop_exc)):
|
||||
try:
|
||||
with woohoo():
|
||||
raise stop_exc
|
||||
except Exception as ex:
|
||||
self.assertIs(ex, stop_exc)
|
||||
else:
|
||||
self.fail(f'{stop_exc} was suppressed')
|
||||
|
||||
def test_contextmanager_except_pep479(self):
|
||||
code = """\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue