Skip to content

Commit a9fe604

Browse files
committed
use pytest timeout exception when not expecting events
1 parent ef4e35a commit a9fe604

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

webdriver/tests/bidi/external/speculation/prefetch_status_updated/prefetch_status_updated.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,8 @@ async def test_subscribe_unsubscribe_event_emission(
248248
with wait_for_events(["speculation.prefetchStatusUpdated"]) as waiter:
249249
await add_speculation_rules_and_link(new_tab, speculation_rules_2, prefetch_target_2)
250250

251-
# Wait briefly and then check if no events were received
252-
try:
253-
# This should timeout since no events should come
251+
with pytest.raises(TimeoutException):
254252
await waiter.get_events(lambda events: len(events) >= 1, timeout=2)
255-
assert False, "Should not have received any events after unsubscribing"
256-
except TimeoutException:
257-
# This is expected - no events should be received
258-
pass
259-
260-
# Double check that no events were collected
261-
assert len(waiter.events) == 0, f"Expected no events after unsubscribing, got {len(waiter.events)}: {waiter.events}"
262-
263253

264254
@pytest.mark.asyncio
265255
async def test_subscribe_unsubscribe_module_subscription(
@@ -319,17 +309,8 @@ async def test_subscribe_unsubscribe_module_subscription(
319309
with wait_for_events(["speculation.prefetchStatusUpdated"]) as waiter:
320310
await add_speculation_rules_and_link(new_tab, speculation_rules_2, prefetch_target_2)
321311

322-
# Wait briefly and then check if no events were received
323-
try:
324-
# This should timeout since no events should come
325-
await waiter.get_events(lambda events: len(events) >= 1, timeout=3)
326-
assert False, "Should not have received any events after unsubscribing from module"
327-
except TimeoutException:
328-
# This is expected - no events should be received
329-
pass
330-
331-
# Double check that no events were collected
332-
assert len(waiter.events) == 0, f"Expected no events after unsubscribing from module, got {len(waiter.events)}: {waiter.events}"
312+
with pytest.raises(TimeoutException):
313+
await waiter.get_events(lambda events: len(events) >= 1, timeout=2)
333314

334315
@pytest.mark.asyncio
335316
async def test_unsubscribe_from_prefetch_status_updated(

0 commit comments

Comments
 (0)