From 08b2d884a978f9ab9ad63c4c89bd44b79c43e0a1 Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Jun 27 2018 18:55:57 +0000 Subject: Issue 49717 - Add conftest.py for tests Bug Description: From the test's output it's not possible to tell what version of 389-ds-base was used during the test, what are the versions of libraries that we depend on, etc. Fix Description: We can use conftest.py to print this useful information. This also will be reflected in an html report, if py.test is used with --html option. https://pagure.io/389-ds-base/issue/49717 Reviewed by: spichugi, amsharma, mreynolds (Thanks!) --- diff --git a/dirsrvtests/conftest.py b/dirsrvtests/conftest.py new file mode 100644 index 0000000..8442e5e --- /dev/null +++ b/dirsrvtests/conftest.py @@ -0,0 +1,46 @@ +import pytest +import subprocess + +pkgs = ['389-ds-base', 'nss', 'nspr', 'openldap', 'cyrus-sasl'] + + +def get_rpm_version(pkg): + try: + result = subprocess.check_output(['rpm', '-q', '--queryformat', + '%{VERSION}-%{RELEASE}', pkg]) + except: + result = b"not installed" + + return result.decode('utf-8') + + +def is_fips(): + # Are we running in FIPS mode? + with open('/proc/sys/crypto/fips_enabled', 'r') as f: + return f.readline() + + +@pytest.fixture(autouse=True) +def _environment(request): + if "_metadata" in dir(request.config): + for pkg in pkgs: + request.config._metadata[pkg] = get_rpm_version(pkg) + request.config._metadata['FIPS'] = is_fips() + + +def pytest_report_header(config): + header = "" + for pkg in pkgs: + header += pkg + ": " + get_rpm_version(pkg) + "\n" + header += "FIPS: " + is_fips() + return header + + +@pytest.mark.optionalhook +def pytest_html_results_table_header(cells): + cells.pop() + + +@pytest.mark.optionalhook +def pytest_html_results_table_row(report, cells): + cells.pop()