Переглянути джерело

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!)
Viktor Ashirov 7 роки тому
батько
коміт
08b2d884a9
1 змінених файлів з 46 додано та 0 видалено
  1. 46 0
      dirsrvtests/conftest.py

+ 46 - 0
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()
+
+
[email protected](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
+
+
[email protected]
+def pytest_html_results_table_header(cells):
+    cells.pop()
+
+
[email protected]
+def pytest_html_results_table_row(report, cells):
+    cells.pop()