]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44469: Fix tests for "async with" with bad object (GH-26817)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 21 Jun 2021 07:21:59 +0000 (10:21 +0300)
committerGitHub <noreply@github.com>
Mon, 21 Jun 2021 07:21:59 +0000 (10:21 +0300)
Test for execution of the body was null. It would pass
even if the code which should be skipped was executed.

Lib/test/test_coroutines.py

index 145adb6778170110914bc95711705be661e79f61..a6a199e323c5f9f99f0e0c4b066371afcbbaa9bb 100644 (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,