Skip to content

Commit 534921a

Browse files
author
rplevka
committed
record start_time property workaround for pytest-dev/pytest#7767
1 parent 3bf9c0c commit 534921a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/foreman/conftest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
from pytest_reportportal import RPLogger, RPLogHandler
1010
except ImportError:
1111
pass
12+
from _pytest.junitxml import xml_key
1213
from robottelo.config import settings
1314
from robottelo.decorators import setting_is_set
1415

16+
FMT_XUNIT_TIME = "%Y-%m-%dT%H:%M:%S"
1517

1618
def log(message, level="DEBUG"):
1719
"""Pytest has a limitation to use logging.logger from conftest.py
@@ -45,7 +47,13 @@ def pytest_report_header(config):
4547
shared_function_enabled, scope, storage
4648
)
4749
)
48-
50+
# workaround for https://github.com/pytest-dev/pytest/issues/7767
51+
# remove if resolved and set autouse=True for record_testsuite_timestamp_xml fixture
52+
if config.pluginmanager.hasplugin("junitxml"):
53+
now = datetime.datetime.utcnow()
54+
xml = config._store.get(xml_key, None)
55+
if xml:
56+
xml.add_global_property('start_time', now.strftime(FMT_XUNIT_TIME))
4957
return messages
5058

5159

@@ -139,13 +147,13 @@ def pytest_collection_modifyitems(session, items, config):
139147
items[:] = [item for item in items if item not in deselected_items]
140148

141149

142-
@pytest.fixture(autouse=True, scope="session")
150+
@pytest.fixture(autouse=False, scope="session")
143151
def record_testsuite_timestamp_xml(record_testsuite_property):
144152
now = datetime.datetime.utcnow()
145-
record_testsuite_property("start_time", now.strftime("%Y-%m-%dT%H:%M:%S"))
153+
record_testsuite_property("start_time", now.strftime(FMT_XUNIT_TIME))
146154

147155

148156
@pytest.fixture(autouse=True, scope="function")
149157
def record_test_timestamp_xml(record_property):
150158
now = datetime.datetime.utcnow()
151-
record_property("start_time", now.strftime("%Y-%m-%dT%H:%M:%S"))
159+
record_property("start_time", now.strftime(FMT_XUNIT_TIME))

0 commit comments

Comments
 (0)