@@ -169,7 +169,9 @@ async def test_enqueue_event_propagates_to_children(
169169
170170
171171@pytest .mark .asyncio
172- async def test_enqueue_event_when_closed (event_queue : EventQueue ) -> None :
172+ async def test_enqueue_event_when_closed (
173+ event_queue : EventQueue , expected_queue_closed_exception
174+ ) -> None :
173175 """Test that no event is enqueued if the parent queue is closed."""
174176 await event_queue .close () # Close the queue first
175177
@@ -178,7 +180,7 @@ async def test_enqueue_event_when_closed(event_queue: EventQueue) -> None:
178180 await event_queue .enqueue_event (event )
179181
180182 # Verify the queue is still empty
181- with pytest .raises (asyncio . QueueEmpty ):
183+ with pytest .raises (expected_queue_closed_exception ):
182184 await event_queue .dequeue_event (no_wait = True )
183185
184186 # Also verify child queues are not affected directly by parent's enqueue attempt when closed
@@ -192,7 +194,7 @@ async def test_enqueue_event_when_closed(event_queue: EventQueue) -> None:
192194 await (
193195 child_queue .close ()
194196 ) # ensure child is also seen as closed for this test's purpose
195- with pytest .raises (asyncio . QueueEmpty ):
197+ with pytest .raises (expected_queue_closed_exception ):
196198 await child_queue .dequeue_event (no_wait = True )
197199
198200
@@ -214,7 +216,7 @@ async def test_dequeue_event_closed_and_empty_no_wait(
214216 with pytest .raises (expected_queue_closed_exception ):
215217 event_queue .queue .get_nowait ()
216218
217- with pytest .raises (asyncio . QueueEmpty , match = 'Queue is closed.' ):
219+ with pytest .raises (expected_queue_closed_exception ):
218220 await event_queue .dequeue_event (no_wait = True )
219221
220222
@@ -230,7 +232,8 @@ async def test_dequeue_event_closed_and_empty_waits_then_raises(
230232
231233 # This test is tricky because await event_queue.dequeue_event() would hang if not for the close check.
232234 # The current implementation's dequeue_event checks `is_closed` first.
233- # If closed and empty, it raises QueueEmpty immediately.
235+ # If closed and empty, it raises QueueEmpty immediately (on Python <= 3.12).
236+ # On Python 3.13+, this check is skipped and asyncio.Queue.get() raises QueueShutDown instead.
234237 # The "waits_then_raises" scenario described in the subtask implies the `get()` might wait.
235238 # However, the current code:
236239 # async with self._lock:
@@ -240,7 +243,7 @@ async def test_dequeue_event_closed_and_empty_waits_then_raises(
240243 # event = await self.queue.get() -> this line is not reached if closed and empty.
241244
242245 # So, for the current implementation, it will raise QueueEmpty immediately.
243- with pytest .raises (asyncio . QueueEmpty , match = 'Queue is closed.' ):
246+ with pytest .raises (expected_queue_closed_exception ):
244247 await event_queue .dequeue_event (no_wait = False )
245248
246249 # If the implementation were to change to allow `await self.queue.get()`
0 commit comments