Patch PyTest's log handlers

This commit is contained in:
Pedro Algarvio 2018-12-01 15:41:09 +00:00
parent 2d2e1e1f96
commit b3d82cb189
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -34,6 +34,7 @@ from tests.integration import TestDaemon
# Import pytest libs
import pytest
import _pytest.logging
from _pytest.terminal import TerminalReporter
# Import 3rd-party libs
@ -44,6 +45,7 @@ from salt.ext import six
import salt.utils.files
import salt.utils.path
import salt.log.setup
import salt.log.mixins
from salt.utils.odict import OrderedDict
# Define the pytest plugins we rely on
@ -52,13 +54,37 @@ pytest_plugins = ['tempdir', 'helpers_namespace', 'salt-runtests-bridge'] # pyl
# Define where not to collect tests from
collect_ignore = ['setup.py']
log = logging.getLogger('salt.testsuite')
# Patch PyTest logging handlers
class LogCaptureHandler(salt.log.mixins.ExcInfoOnLogLevelFormatMixIn,
_pytest.logging.LogCaptureHandler):
'''
Subclassing PyTest's LogCaptureHandler in order to add the
exc_info_on_loglevel functionality.
'''
_pytest.logging.LogCaptureHandler = LogCaptureHandler
class LiveLoggingStreamHandler(salt.log.mixins.ExcInfoOnLogLevelFormatMixIn,
_pytest.logging._LiveLoggingStreamHandler):
'''
Subclassing PyTest's LiveLoggingStreamHandler in order to add the
exc_info_on_loglevel functionality.
'''
_pytest.logging._LiveLoggingStreamHandler = LiveLoggingStreamHandler
# Reset logging root handlers
for handler in logging.root.handlers:
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
log = logging.getLogger('salt.testsuite')
def pytest_tempdir_basename():
'''
Return the temporary directory basename for the salt test suite.