File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -1540,23 +1540,33 @@ class AsyncTests(BaseTest):
1540
1540
def test_async_context (self ):
1541
1541
import asyncio
1542
1542
1543
+ # Events to force the execution interleaving we want.
1544
+ step_a1 = asyncio .Event ()
1545
+ step_a2 = asyncio .Event ()
1546
+ step_b1 = asyncio .Event ()
1547
+ step_b2 = asyncio .Event ()
1548
+
1543
1549
async def run_a ():
1544
1550
with self .module .catch_warnings (record = True ) as w :
1545
- await asyncio . sleep ( 0 )
1551
+ await step_a1 . wait ( )
1546
1552
# The warning emitted here should be caught be the enclosing
1547
1553
# context manager.
1548
1554
self .module .warn ('run_a warning' , UserWarning )
1549
- await asyncio .sleep (0 )
1555
+ step_b1 .set ()
1556
+ await step_a2 .wait ()
1550
1557
self .assertEqual (len (w ), 1 )
1551
1558
self .assertEqual (w [0 ].message .args [0 ], 'run_a warning' )
1559
+ step_b2 .set ()
1552
1560
1553
1561
async def run_b ():
1554
1562
with self .module .catch_warnings (record = True ) as w :
1555
- await asyncio .sleep (0 )
1563
+ step_a1 .set ()
1564
+ await step_b1 .wait ()
1556
1565
# The warning emitted here should be caught be the enclosing
1557
1566
# context manager.
1558
1567
self .module .warn ('run_b warning' , UserWarning )
1559
- await asyncio .sleep (0 )
1568
+ step_a2 .set ()
1569
+ await step_b2 .wait ()
1560
1570
self .assertEqual (len (w ), 1 )
1561
1571
self .assertEqual (w [0 ].message .args [0 ], 'run_b warning' )
1562
1572
You can’t perform that action at this time.
0 commit comments