diff --git a/tests/helpers/logfail.py b/tests/helpers/logfail.py index b95f40626..dc70f4e29 100644 --- a/tests/helpers/logfail.py +++ b/tests/helpers/logfail.py @@ -40,7 +40,6 @@ class LogFailHandler(logging.Handler): def __init__(self, level=logging.NOTSET, min_level=logging.WARNING): self._min_level = min_level - self.failed = False super().__init__(level) def emit(self, record): @@ -63,7 +62,9 @@ class LogFailHandler(logging.Handler): return if record.levelno < self._min_level: return - self.failed = True + pytest.fail("Got logging message on logger {} with level {}: " + "{}!".format(record.name, record.levelname, + record.getMessage())) @pytest.yield_fixture(scope='session', autouse=True) @@ -73,8 +74,6 @@ def fail_on_logging(): yield logging.getLogger().removeHandler(handler) handler.close() - if handler.failed: - pytest.fail("Got unexpected logging message!", pytrace=False) @pytest.yield_fixture(autouse=True) diff --git a/tests/helpers/test_logfail.py b/tests/helpers/test_logfail.py index 2acbdd193..c66eb9296 100644 --- a/tests/helpers/test_logfail.py +++ b/tests/helpers/test_logfail.py @@ -125,48 +125,6 @@ def test_log_expected_wrong_logger(log_testdir): res.stdout.fnmatch_lines(['*1 error*']) -def test_output_passing(log_testdir): - log_testdir.makepyfile(""" - import logging - - def test_foo(): - logging.error('log msg 1') - logging.error('log msg 2') - """) - res = log_testdir.runpytest('-p capturelog') - res.stdout.fnmatch_lines([ - '*= ERRORS =*', - '*_ ERROR at teardown of test_foo _*', - 'Got unexpected logging message!', - - '*1 error*', - ]) - - -def test_output_failing(log_testdir): - log_testdir.makepyfile(""" - import logging - - def test_foo(): - logging.error('log msg 1') - logging.error('log msg 2') - raise Exception - """) - res = log_testdir.runpytest('-p capturelog') - res.stdout.fnmatch_lines([ - '*= ERRORS =*', - '*_ ERROR at teardown of test_foo _*', - 'Got unexpected logging message!', - - '*= FAILURES =*', - '*- Captured log -*', - '*ERROR log msg 1', - '*ERROR log msg 2', - - '*1 error*', - ]) - - @pytest.fixture def skipping_fixture(): pytest.skip("Skipping to test caplog workaround.")