[Python-checkins] bpo-44469: Fix tests for "async with" with bad object (GH-26817)
miss-islington
webhook-mailer at python.org
Mon Jun 21 03:54:12 EDT 2021
https://github.com/python/cpython/commit/175e264d363164c905b08688bbda751c9ff26342
commit: 175e264d363164c905b08688bbda751c9ff26342
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021年06月21日T00:54:04-07:00
summary:
bpo-44469: Fix tests for "async with" with bad object (GH-26817)
Test for execution of the body was null. It would pass
even if the code which should be skipped was executed.
(cherry picked from commit 5d2b3a0d688cf8a33db3d266c9e7049c13766a4c)
Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>
files:
M Lib/test/test_coroutines.py
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index 8d1e0692a24221..1e01e3be83cda1 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -1203,41 +1203,47 @@ class CM:
def __aenter__(self):
pass
- body_executed = False
+ body_executed = None
async def foo():
+ nonlocal body_executed
+ body_executed = False
async with CM():
body_executed = True
with self.assertRaisesRegex(AttributeError, '__aexit__'):
run_async(foo())
- self.assertFalse(body_executed)
+ self.assertIs(body_executed, False)
def test_with_3(self):
class CM:
def __aexit__(self):
pass
- body_executed = False
+ body_executed = None
async def foo():
+ nonlocal body_executed
+ body_executed = False
async with CM():
body_executed = True
with self.assertRaisesRegex(AttributeError, '__aenter__'):
run_async(foo())
- self.assertFalse(body_executed)
+ self.assertIs(body_executed, False)
def test_with_4(self):
class CM:
pass
- body_executed = False
+ body_executed = None
async def foo():
+ nonlocal body_executed
+ body_executed = False
async with CM():
body_executed = True
with self.assertRaisesRegex(AttributeError, '__aenter__'):
run_async(foo())
- self.assertFalse(body_executed)
+ self.assertIs(body_executed, False)
def test_with_5(self):
# While this test doesn't make a lot of sense,
More information about the Python-checkins
mailing list