diff options
author | Géry Ogam <gery.ogam@gmail.com> | 2020-01-14 11:58:29 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2020-01-14 11:58:29 (GMT) |
commit | 1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d (patch) | |
tree | 1cecc3868d762cd3e1c2414520d954dfe05aea17 /Lib/test/test_coroutines.py | |
parent | 9af0e47b1705457bb6b327c197f2ec5737a1d8f6 (diff) | |
download | cpython-1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d.zip cpython-1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d.tar.gz cpython-1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d.tar.bz2 |
bpo-39048: Look up __aenter__ before __aexit__ in async with (GH-17609)
* Reorder the __aenter__ and __aexit__ checks for async with
* Add assertions for async with body being skipped
* Swap __aexit__ and __aenter__ loading in the documentation
Diffstat (limited to 'Lib/test/test_coroutines.py')
-rw-r--r-- | Lib/test/test_coroutines.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py index 208b5c2..8d1e069 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -1203,39 +1203,41 @@ class CoroutineTest(unittest.TestCase): def __aenter__(self): pass + body_executed = False async def foo(): async with CM(): - pass + body_executed = True with self.assertRaisesRegex(AttributeError, '__aexit__'): run_async(foo()) + self.assertFalse(body_executed) def test_with_3(self): class CM: def __aexit__(self): pass + body_executed = False async def foo(): async with CM(): - pass + body_executed = True with self.assertRaisesRegex(AttributeError, '__aenter__'): run_async(foo()) + self.assertFalse(body_executed) def test_with_4(self): class CM: - def __enter__(self): - pass - - def __exit__(self): - pass + pass + body_executed = False async def foo(): async with CM(): - pass + body_executed = True - with self.assertRaisesRegex(AttributeError, '__aexit__'): + with self.assertRaisesRegex(AttributeError, '__aenter__'): run_async(foo()) + self.assertFalse(body_executed) def test_with_5(self): # While this test doesn't make a lot of sense, |