mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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.
This commit is contained in:
parent
a317778fd5
commit
5d2b3a0d68
1 changed files with 12 additions and 6 deletions
|
@ -1205,41 +1205,47 @@ class CoroutineTest(unittest.TestCase):
|
||||||
def __aenter__(self):
|
def __aenter__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
body_executed = False
|
body_executed = None
|
||||||
async def foo():
|
async def foo():
|
||||||
|
nonlocal body_executed
|
||||||
|
body_executed = False
|
||||||
async with CM():
|
async with CM():
|
||||||
body_executed = True
|
body_executed = True
|
||||||
|
|
||||||
with self.assertRaisesRegex(AttributeError, '__aexit__'):
|
with self.assertRaisesRegex(AttributeError, '__aexit__'):
|
||||||
run_async(foo())
|
run_async(foo())
|
||||||
self.assertFalse(body_executed)
|
self.assertIs(body_executed, False)
|
||||||
|
|
||||||
def test_with_3(self):
|
def test_with_3(self):
|
||||||
class CM:
|
class CM:
|
||||||
def __aexit__(self):
|
def __aexit__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
body_executed = False
|
body_executed = None
|
||||||
async def foo():
|
async def foo():
|
||||||
|
nonlocal body_executed
|
||||||
|
body_executed = False
|
||||||
async with CM():
|
async with CM():
|
||||||
body_executed = True
|
body_executed = True
|
||||||
|
|
||||||
with self.assertRaisesRegex(AttributeError, '__aenter__'):
|
with self.assertRaisesRegex(AttributeError, '__aenter__'):
|
||||||
run_async(foo())
|
run_async(foo())
|
||||||
self.assertFalse(body_executed)
|
self.assertIs(body_executed, False)
|
||||||
|
|
||||||
def test_with_4(self):
|
def test_with_4(self):
|
||||||
class CM:
|
class CM:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
body_executed = False
|
body_executed = None
|
||||||
async def foo():
|
async def foo():
|
||||||
|
nonlocal body_executed
|
||||||
|
body_executed = False
|
||||||
async with CM():
|
async with CM():
|
||||||
body_executed = True
|
body_executed = True
|
||||||
|
|
||||||
with self.assertRaisesRegex(AttributeError, '__aenter__'):
|
with self.assertRaisesRegex(AttributeError, '__aenter__'):
|
||||||
run_async(foo())
|
run_async(foo())
|
||||||
self.assertFalse(body_executed)
|
self.assertIs(body_executed, False)
|
||||||
|
|
||||||
def test_with_5(self):
|
def test_with_5(self):
|
||||||
# While this test doesn't make a lot of sense,
|
# While this test doesn't make a lot of sense,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue