Skip to content

Commit 7a95324

Browse files
update unit tests to work with py3.13
1 parent f2f1ffc commit 7a95324

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tests/server/events/test_event_queue.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ 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:
173-
"""Test that no event is enqueued if the parent queue is closed."""
172+
async def test_enqueue_event_when_closed(event_queue: EventQueue, expected_queue_closed_exception) -> None:
173+
"""Test that no event is enqueued if the parent queue is closed."""
174174
await event_queue.close() # Close the queue first
175175

176176
event = Message(**MESSAGE_PAYLOAD)
177177
# Attempt to enqueue, should do nothing or log a warning as per implementation
178178
await event_queue.enqueue_event(event)
179179

180180
# Verify the queue is still empty
181-
with pytest.raises(asyncio.QueueEmpty):
181+
with pytest.raises(expected_queue_closed_exception):
182182
await event_queue.dequeue_event(no_wait=True)
183183

184184
# Also verify child queues are not affected directly by parent's enqueue attempt when closed
@@ -192,7 +192,7 @@ async def test_enqueue_event_when_closed(event_queue: EventQueue) -> None:
192192
await (
193193
child_queue.close()
194194
) # ensure child is also seen as closed for this test's purpose
195-
with pytest.raises(asyncio.QueueEmpty):
195+
with pytest.raises(expected_queue_closed_exception):
196196
await child_queue.dequeue_event(no_wait=True)
197197

198198

@@ -214,7 +214,7 @@ async def test_dequeue_event_closed_and_empty_no_wait(
214214
with pytest.raises(expected_queue_closed_exception):
215215
event_queue.queue.get_nowait()
216216

217-
with pytest.raises(asyncio.QueueEmpty, match='Queue is closed.'):
217+
with pytest.raises(expected_queue_closed_exception):
218218
await event_queue.dequeue_event(no_wait=True)
219219

220220

@@ -230,7 +230,8 @@ async def test_dequeue_event_closed_and_empty_waits_then_raises(
230230

231231
# This test is tricky because await event_queue.dequeue_event() would hang if not for the close check.
232232
# The current implementation's dequeue_event checks `is_closed` first.
233-
# If closed and empty, it raises QueueEmpty immediately.
233+
# If closed and empty, it raises QueueEmpty immediately (on Python <= 3.12).
234+
# On Python 3.13+, this check is skipped and asyncio.Queue.get() raises QueueShutDown instead.
234235
# The "waits_then_raises" scenario described in the subtask implies the `get()` might wait.
235236
# However, the current code:
236237
# async with self._lock:
@@ -240,7 +241,7 @@ async def test_dequeue_event_closed_and_empty_waits_then_raises(
240241
# event = await self.queue.get() -> this line is not reached if closed and empty.
241242

242243
# So, for the current implementation, it will raise QueueEmpty immediately.
243-
with pytest.raises(asyncio.QueueEmpty, match='Queue is closed.'):
244+
with pytest.raises(expected_queue_closed_exception):
244245
await event_queue.dequeue_event(no_wait=False)
245246

246247
# If the implementation were to change to allow `await self.queue.get()`

0 commit comments

Comments
 (0)