diff --git a/pytest_catchlog/fixture.py b/pytest_catchlog/fixture.py index c33a3b5..8984944 100644 --- a/pytest_catchlog/fixture.py +++ b/pytest_catchlog/fixture.py @@ -18,6 +18,9 @@ def __init__(self): self.records = [] def emit(self, record): # Called with the lock acquired. + if not hasattr(record, 'message'): + record.message = record.getMessage() + record.getMessage = lambda: record.message self.records.append(record) diff --git a/tests/test_fixture.py b/tests/test_fixture.py index 06829a2..146bee3 100644 --- a/tests/test_fixture.py +++ b/tests/test_fixture.py @@ -65,3 +65,21 @@ def test_unicode(caplog): assert caplog.records[0].levelname == 'INFO' assert caplog.records[0].msg == u('bū') assert u('bū') in caplog.text + + +def test_record_message_text(caplog): + mutable = {} + logger.info("Mutable dict %r empty", mutable) + mutable['foo'] = 'bar' + logger.info("Mutable dict %r bar", mutable) + mutable['foo'] = 'baz' + logger.info("Mutable dict %r baz", mutable) + + assert caplog.record_tuples == [ + (__name__, logging.INFO, "Mutable dict {} empty"), + (__name__, logging.INFO, "Mutable dict {'foo': 'bar'} bar"), + (__name__, logging.INFO, "Mutable dict {'foo': 'baz'} baz"), + ] + assert caplog.text == ("INFO:test_fixture:Mutable dict {} empty\n" + "INFO:test_fixture:Mutable dict {'foo': 'bar'} bar\n" + "INFO:test_fixture:Mutable dict {'foo': 'baz'} baz\n")