From: Rafael Zalamena Date: Thu, 27 Jul 2017 17:52:51 +0000 (-0300) Subject: topotests: make asserts show up in stderr X-Git-Tag: frr-7.1-dev~151^2~239 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e7ba3cd11c0fded7d8563a0eebb1ed888f298ebb;p=mirror%2Ffrr.git topotests: make asserts show up in stderr Code was based on the pytest default makereport code: https://github.com/pytest-dev/pytest/blob/c92760dca8637251eb9e7b9ea4819b32bc0b8042/_pytest/runner.py#L264 --- diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py index 05ac329488..43f9516a11 100755 --- a/tests/topotests/conftest.py +++ b/tests/topotests/conftest.py @@ -4,6 +4,7 @@ Topotest conftest.py file. from lib.topogen import get_topogen, diagnose_env from lib.topotest import json_cmp_result +from lib.topolog import logger import pytest def pytest_addoption(parser): @@ -45,3 +46,21 @@ def pytest_configure(config): "Assert that the environment is correctly configured." if not diagnose_env(): pytest.exit('enviroment has errors, please read the logs') + +def pytest_runtest_makereport(item, call): + "Log all assert messages to default logger with error level" + # Nothing happened + if call.excinfo is None: + return + + # Treat skips as non errors + if call.excinfo.typename != 'AssertionError': + logger.info('assert skipped at "{}": {}'.format( + item.name, call.excinfo.value)) + return + + # Handle assert failures + parent = item.parent + parent._previousfailed = item + logger.error('assert failed at "{}": {}'.format( + item.name, call.excinfo.value))