summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_coroutines.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-21 07:57:07 (GMT)
committerGitHub <noreply@github.com>2021-06-21 07:57:07 (GMT)
commit553e10498ac2020e9abdb5302c91bfb235925cef (patch)
tree47ea017b8beb9873c9a129d83ef4d032efc3679d /Lib/test/test_coroutines.py
parentccc95c7b4799570c2d7e4de3d579860ad833e1f8 (diff)
downloadcpython-553e10498ac2020e9abdb5302c91bfb235925cef.zip
cpython-553e10498ac2020e9abdb5302c91bfb235925cef.tar.gz
cpython-553e10498ac2020e9abdb5302c91bfb235925cef.tar.bz2
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@gmail.com>
Diffstat (limited to 'Lib/test/test_coroutines.py')
-rw-r--r--Lib/test/test_coroutines.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index 145adb6..a6a199e 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -1205,41 +1205,47 @@ class CoroutineTest(unittest.TestCase):
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,