Skip to content

Commit 5d2b3a0

Browse files
bpo-44469: Fix tests for "async with" with bad object (pythonGH-26817)
Test for execution of the body was null. It would pass even if the code which should be skipped was executed.
1 parent a317778 commit 5d2b3a0

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

Lib/test/test_coroutines.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,41 +1205,47 @@ class CM:
12051205
def __aenter__(self):
12061206
pass
12071207

1208-
body_executed = False
1208+
body_executed = None
12091209
async def foo():
1210+
nonlocal body_executed
1211+
body_executed = False
12101212
async with CM():
12111213
body_executed = True
12121214

12131215
with self.assertRaisesRegex(AttributeError, '__aexit__'):
12141216
run_async(foo())
1215-
self.assertFalse(body_executed)
1217+
self.assertIs(body_executed, False)
12161218

12171219
def test_with_3(self):
12181220
class CM:
12191221
def __aexit__(self):
12201222
pass
12211223

1222-
body_executed = False
1224+
body_executed = None
12231225
async def foo():
1226+
nonlocal body_executed
1227+
body_executed = False
12241228
async with CM():
12251229
body_executed = True
12261230

12271231
with self.assertRaisesRegex(AttributeError, '__aenter__'):
12281232
run_async(foo())
1229-
self.assertFalse(body_executed)
1233+
self.assertIs(body_executed, False)
12301234

12311235
def test_with_4(self):
12321236
class CM:
12331237
pass
12341238

1235-
body_executed = False
1239+
body_executed = None
12361240
async def foo():
1241+
nonlocal body_executed
1242+
body_executed = False
12371243
async with CM():
12381244
body_executed = True
12391245

12401246
with self.assertRaisesRegex(AttributeError, '__aenter__'):
12411247
run_async(foo())
1242-
self.assertFalse(body_executed)
1248+
self.assertIs(body_executed, False)
12431249

12441250
def test_with_5(self):
12451251
# While this test doesn't make a lot of sense,

0 commit comments

Comments
 (0)