From 56ea32d66c602b1d160b240046ad801d2c1afcae Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Sep 23 2019 08:00:49 +0000 Subject: Issue 50615 - Log current test name to journald Bug Description: Sometimes server crashes during test execution, events about crash are logged to journald. But it's not easy to tell in which test the crash happened, especially during the full test run. Fix Description: Add a fixture that is used automatically for all tests (if the server is built with systemd) on setup and teardown, and logs a message to journald Fixes: https://pagure.io/389-ds-base/issue/50615 Reviewed by: mreynolds (Thanks!) --- diff --git a/dirsrvtests/conftest.py b/dirsrvtests/conftest.py index cee9e8b..70a6d5a 100644 --- a/dirsrvtests/conftest.py +++ b/dirsrvtests/conftest.py @@ -3,6 +3,7 @@ import logging import pytest import os +from lib389.paths import Paths from enum import Enum pkgs = ['389-ds-base', 'nss', 'nspr', 'openldap', 'cyrus-sasl'] @@ -69,3 +70,15 @@ def pytest_html_results_table_header(cells): @pytest.mark.optionalhook def pytest_html_results_table_row(report, cells): cells.pop() + + +@pytest.fixture(scope="function", autouse=True) +def log_test_name_to_journald(request): + p = Paths() + if p.with_systemd: + def log_current_test(): + subprocess.Popen("echo $PYTEST_CURRENT_TEST | systemd-cat -t pytest", stdin=subprocess.PIPE, shell=True) + + log_current_test() + request.addfinalizer(log_current_test) + return log_test_name_to_journald