Skip to content

Commit e86bdce

Browse files
committed
capture expected warnings in the test
1 parent 57876e7 commit e86bdce

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tests/test_asyncio/test_connection.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ async def mock_aclose(self):
316316
url: str = request.config.getoption("--redis-url")
317317
r1 = await Redis.from_url(url)
318318
with patch.object(r1, "aclose", mock_aclose):
319-
await r1.close()
319+
with pytest.deprecated_call():
320+
await r1.close()
320321
assert calls == 1
321322

322323
with pytest.deprecated_call():
@@ -453,8 +454,9 @@ async def test_client_garbage_collection(request):
453454
with mock.patch.object(client, "connection") as a:
454455
# we cannot, in unittests, or from asyncio, reliably trigger garbage collection
455456
# so we must just invoke the handler
456-
client.__del__()
457-
assert a._close.called
457+
with pytest.warns(ResourceWarning):
458+
client.__del__()
459+
assert a._close.called
458460

459461
await client.aclose()
460462
await pool.aclose()
@@ -478,8 +480,9 @@ async def test_connection_garbage_collection(request):
478480
with mock.patch.object(conn, "_writer") as a:
479481
# we cannot, in unittests, or from asyncio, reliably trigger garbage collection
480482
# so we must just invoke the handler
481-
conn.__del__()
482-
assert a.close.called
483+
with pytest.warns(ResourceWarning):
484+
conn.__del__()
485+
assert a.close.called
483486

484487
await client.aclose()
485488
await pool.aclose()

0 commit comments

Comments
 (0)