From e7ba3cd11c0fded7d8563a0eebb1ed888f298ebb Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 27 Jul 2017 14:52:51 -0300 Subject: [PATCH] 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 --- tests/topotests/conftest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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)) -- 2.39.5