Revert "logfail: Continue running test and fail afterwards."
This reverts commit 66ed4e9c4e
.
This commit is contained in:
parent
d18c33987d
commit
f7c405d2f4
@ -40,7 +40,6 @@ class LogFailHandler(logging.Handler):
|
|||||||
|
|
||||||
def __init__(self, level=logging.NOTSET, min_level=logging.WARNING):
|
def __init__(self, level=logging.NOTSET, min_level=logging.WARNING):
|
||||||
self._min_level = min_level
|
self._min_level = min_level
|
||||||
self.failed = False
|
|
||||||
super().__init__(level)
|
super().__init__(level)
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
@ -63,7 +62,9 @@ class LogFailHandler(logging.Handler):
|
|||||||
return
|
return
|
||||||
if record.levelno < self._min_level:
|
if record.levelno < self._min_level:
|
||||||
return
|
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)
|
@pytest.yield_fixture(scope='session', autouse=True)
|
||||||
@ -73,8 +74,6 @@ def fail_on_logging():
|
|||||||
yield
|
yield
|
||||||
logging.getLogger().removeHandler(handler)
|
logging.getLogger().removeHandler(handler)
|
||||||
handler.close()
|
handler.close()
|
||||||
if handler.failed:
|
|
||||||
pytest.fail("Got unexpected logging message!", pytrace=False)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture(autouse=True)
|
@pytest.yield_fixture(autouse=True)
|
||||||
|
@ -125,48 +125,6 @@ def test_log_expected_wrong_logger(log_testdir):
|
|||||||
res.stdout.fnmatch_lines(['*1 error*'])
|
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
|
@pytest.fixture
|
||||||
def skipping_fixture():
|
def skipping_fixture():
|
||||||
pytest.skip("Skipping to test caplog workaround.")
|
pytest.skip("Skipping to test caplog workaround.")
|
||||||
|
Loading…
Reference in New Issue
Block a user