Skip to content

Commit 0f08774

Browse files
committed
Use caplog fixture instead of mocking log calls
1 parent f243311 commit 0f08774

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

t/unit/transport/virtual/test_base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import io
4+
import logging
45
import socket
56
import sys
67
import warnings
@@ -17,7 +18,6 @@
1718
from kombu.utils.uuid import uuid
1819

1920
PRINT_FQDN = 'builtins.print'
20-
LOG_FQDN = 'logging.Logger._log'
2121

2222

2323
def client(**kwargs):
@@ -413,11 +413,10 @@ def test_restore_unacked_raises_BaseException(self):
413413
assert not q._delivered
414414

415415
@patch('kombu.transport.virtual.base.emergency_dump_state')
416-
@patch(LOG_FQDN)
417416
@patch(PRINT_FQDN)
418417
@pytest.mark.parametrize("stderr_set", [True, False])
419-
def test_restore_unacked_once_when_unrestored(self, print_, log_,
420-
emergency_dump_state, stderr_set):
418+
def test_restore_unacked_once_when_unrestored(self, print_,
419+
emergency_dump_state, stderr_set, caplog):
421420
stderr = sys.stderr if stderr_set else None
422421
q = self.channel.qos
423422
q._flush = Mock()
@@ -435,12 +434,14 @@ class State(dict):
435434
ru.return_value = [(exc, 1)]
436435

437436
self.channel.do_restore = True
438-
q.restore_unacked_once(stderr=stderr)
437+
with caplog.at_level(logging.INFO, logger="kombu.transport.virtual.base"):
438+
q.restore_unacked_once(stderr=stderr)
439439
if stderr_set:
440440
print_.assert_called()
441-
log_.assert_not_called()
441+
assert not caplog.messages
442442
else:
443-
log_.assert_called()
443+
assert caplog.messages[0].startswith("Restoring")
444+
assert caplog.messages[0].endswith("unacknowledged message(s)")
444445
print_.assert_not_called()
445446

446447
emergency_dump_state.assert_called()

0 commit comments

Comments
 (0)