Skip to content

Commit

Permalink
(WIP) Test
Browse files Browse the repository at this point in the history
  • Loading branch information
abusalimov committed Apr 5, 2016
1 parent fe1558c commit 5aabdae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pytest_catchlog/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
18 changes: 18 additions & 0 deletions tests/test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 5aabdae

Please sign in to comment.