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 5d2b3a0d68)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-06-21 00:57:07 -07:00 committed by GitHub
parent ccc95c7b47
commit 553e10498a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,