Skip to content

Commit 9b08d01

Browse files
committed
improve testing
1 parent c75bb2c commit 9b08d01

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/service-library/tests/redis/test_semaphore.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,16 @@ async def delayed_release() -> None:
281281
await semaphore2.release()
282282

283283

284+
@pytest.mark.parametrize(
285+
"exception",
286+
[RuntimeError, asyncio.CancelledError],
287+
ids=str,
288+
)
284289
async def test_semaphore_context_manager_with_exception(
285290
redis_client_sdk: RedisClientSDK,
286291
semaphore_name: str,
287292
semaphore_capacity: int,
293+
exception: type[Exception | asyncio.CancelledError],
288294
):
289295
captured_semaphore: DistributedSemaphore | None = None
290296

@@ -296,10 +302,9 @@ async def _raising_context():
296302
) as sem:
297303
nonlocal captured_semaphore
298304
captured_semaphore = sem
299-
msg = "Test exception"
300-
raise RuntimeError(msg)
305+
raise exception("Test")
301306

302-
with pytest.raises(RuntimeError, match="Test exception"):
307+
with pytest.raises(exception, match="Test"):
303308
await _raising_context()
304309

305310
# Should be released even after exception

0 commit comments

Comments
 (0)