]> git.puffer.fish Git - matthieu/frr.git/commitdiff
topotests: make asserts show up in stderr
authorRafael Zalamena <rzalamena@gmail.com>
Thu, 27 Jul 2017 17:52:51 +0000 (14:52 -0300)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 28 Nov 2018 01:22:12 +0000 (20:22 -0500)
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

index 05ac329488f62a5dfbc2b69ddb1cf0065ba4e4c7..43f9516a11cb58622246880bb0193d37f7f39250 100755 (executable)
@@ -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))