Change caplog.get_handler(when) to caplog.get_records(when)

While updating the docs I noticed that caplog.get_handler() exposes
the underlying Handler object, which I think it is a bit too much
detail at this stage. Update to return the records directly instead.
This commit is contained in:
Bruno Oliveira
2018-01-24 18:59:08 -02:00
parent 2f955e0c99
commit 15cbd61159
4 changed files with 35 additions and 10 deletions

View File

@@ -105,16 +105,16 @@ def logging_during_setup_and_teardown(caplog):
logger.info('a_setup_log')
yield
logger.info('a_teardown_log')
assert [x.message for x in caplog.get_handler('teardown').records] == ['a_teardown_log']
assert [x.message for x in caplog.get_records('teardown')] == ['a_teardown_log']
def test_caplog_captures_for_all_stages(caplog, logging_during_setup_and_teardown):
assert not caplog.records
assert not caplog.get_handler('call').records
assert not caplog.get_records('call')
logger.info('a_call_log')
assert [x.message for x in caplog.get_handler('call').records] == ['a_call_log']
assert [x.message for x in caplog.get_records('call')] == ['a_call_log']
assert [x.message for x in caplog.get_handler('setup').records] == ['a_setup_log']
assert [x.message for x in caplog.get_records('setup')] == ['a_setup_log']
# This reachers into private API, don't use this type of thing in real tests!
assert set(caplog._item.catch_log_handlers.keys()) == {'setup', 'call'}