automation: Enhance pytest header
Mention NetworkManager RPM and Operating System in pytest header. Example: ``` ================= test session starts ================== [...] RPMs: NetworkManager-1.20.5-1.cab2e4fc96.el8.x86_64 OS: CentOS Linux 8 (Core) ``` This makes it easier to identify the test environment from the pytest log. For example when the tests are running on bare-metal or in a VM instead of the container that is setup with run-tests.sh. Signed-off-by: Till Maas <opensource@till.name>
This commit is contained in:
parent
a9ffe156f0
commit
06d10f853f
@ -18,6 +18,7 @@
|
||||
#
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
@ -26,6 +27,11 @@ import libnmstate
|
||||
from .testlib import ifacelib
|
||||
|
||||
|
||||
REPORT_HEADER = """RPMs: {rpms}
|
||||
OS: {osname}
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture(scope='session', autouse=True)
|
||||
def logging_setup():
|
||||
logging.basicConfig(
|
||||
@ -61,3 +67,23 @@ def preserve_old_config():
|
||||
old_state = libnmstate.show()
|
||||
yield
|
||||
libnmstate.apply(old_state, verify_change=False)
|
||||
|
||||
|
||||
def pytest_report_header(config):
|
||||
return REPORT_HEADER.format(
|
||||
rpms=_get_package_nvr('NetworkManager'), osname=_get_osname()
|
||||
)
|
||||
|
||||
|
||||
def _get_package_nvr(package):
|
||||
return (
|
||||
subprocess.check_output(['rpm', '-q', package]).strip().decode('utf-8')
|
||||
)
|
||||
|
||||
|
||||
def _get_osname():
|
||||
with open('/etc/os-release') as os_release:
|
||||
for line in os_release.readlines():
|
||||
if line.startswith('PRETTY_NAME='):
|
||||
return line.split('=', maxsplit=1)[1].strip().strip('"')
|
||||
return ''
|
||||
|
Loading…
x
Reference in New Issue
Block a user