Skip to content

Commit

Permalink
Access captures logs in teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
boxed committed Jan 15, 2018
1 parent 3181718 commit a1a790e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions _pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,16 @@ def _runtest_for(self, item, when):
"""Implements the internals of pytest_runtest_xxx() hook."""
with catching_logs(LogCaptureHandler(),
formatter=self.formatter) as log_handler:
if not hasattr(item, 'catch_log_handlers'):
item.catch_log_handlers = {}
item.catch_log_handlers[when] = log_handler
item.catch_log_handler = log_handler
try:
yield # run test
finally:
del item.catch_log_handler
if when == 'teardown':
del item.catch_log_handlers

if self.print_logs:
# Add a captured log section to the report.
Expand Down

0 comments on commit a1a790e

Please sign in to comment.