Access captures logs in teardown
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
sublogger = logging.getLogger(__name__ + '.baz')
|
||||
@@ -68,3 +69,23 @@ def test_clear(caplog):
|
||||
assert len(caplog.records)
|
||||
caplog.clear()
|
||||
assert not len(caplog.records)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
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']
|
||||
|
||||
|
||||
def test_caplog_captures_for_all_stages(caplog, logging_during_setup_and_teardown):
|
||||
assert not caplog.records
|
||||
assert not caplog.get_handler('call').records
|
||||
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_handler('setup').records] == ['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'}
|
||||
|
||||
Reference in New Issue
Block a user