8000 bpo-44469: Fix tests for "async with" with bad object (GH-26817) · python/cpython@175e264 · GitHub
[go: up one dir, main page]

Skip to content

Commit 175e264

Browse files
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 5d2b3a0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 533bff4 commit 175e264

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Lib/test/test_coroutines.py

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

1206-
body_executed = False
1206+
body_executed = None
12071207
async def foo():
1208+
nonlocal body_executed
1209+
body_executed = False
12081210
async with CM():
12091211
body_executed = True
12101212

12111213
with self.assertRaisesRegex(AttributeError, '__aexit__'):
12121214
run_async(foo())
1213-
self.assertFalse(body_executed)
1215+
self.assertIs(body_executed, False)
12141216

12151217
def test_with_3(self):
12161218
class CM:
12171219
def __aexit__(self):
12181220
pass
12191221

1220-
body_executed = False
1222+
body_executed = None
12211223
async def foo():
1224+
nonlocal body_executed
1225+
body_executed = False
12221226
async with CM():
12231227
body_executed = True
12241228

12251229
with self.assertRaisesRegex(AttributeError, '__aenter__'):
12261230
run_async(foo())
1227-
self.assertFalse(body_executed)
1231+
self.assertIs(body_executed, False)
12281232

12291233
def test_with_4(self):
12301234
class CM:
12311235
pass
12321236

1233-
body_executed = False
1237+
body_executed = None
12341238
async def foo():
1239+
nonlocal body_executed
1240+
body_executed = False
12351241
async with CM():
12361242
body_executed = True
12371243

12381244
with self.assertRaisesRegex(AttributeError, '__aenter__'):
12391245
run_async(foo())
1240-
self.assertFalse(body_executed)
1246+
self.assertIs(body_executed, False)
12411247

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

0 commit comments

Comments
 (0)
0