MCPcopy Create free account
hub / github.com/ElementsProject/lightning / pytest_sessionfinish

Function pytest_sessionfinish

tests/conftest.py:46–89  ·  view source on GitHub ↗

Add environment variables to JUnit XML report. This hook runs on the master node in pytest-xdist to add properties directly to the JUnit XML report. This works around the limitation that record_testsuite_property doesn't work with pytest-xdist. We use tryfirst=True so we run before

(session, exitstatus)

Source from the content-addressed store, hash-verified

44
45@pytest.hookimpl(tryfirst=True)
46def pytest_sessionfinish(session, exitstatus):
47 """Add environment variables to JUnit XML report.
48
49 This hook runs on the master node in pytest-xdist to add properties
50 directly to the JUnit XML report. This works around the limitation
51 that record_testsuite_property doesn't work with pytest-xdist.
52
53 We use tryfirst=True so we run before the junitxml plugin writes the file.
54
55 See: https://github.com/pytest-dev/pytest/issues/7767
56 """
57 # Check if we're on the master node (not a worker)
58 # Workers have the workeroutput attribute
59 if hasattr(session.config, "workeroutput"):
60 return
61
62 # Find the LogXML instance among registered plugins
63 # We need to search through all plugins because it's not directly accessible
64 xml = None
65 for plugin in session.config.pluginmanager.get_plugins():
66 if hasattr(plugin, "add_global_property"):
67 xml = plugin
68 break
69
70 if xml is None:
71 return
72
73 # List of environment variables to include in the report
74 include = [
75 "GITHUB_ACTION_REPOSITORY",
76 "GITHUB_EVENT_NAME",
77 "GITHUB_HEAD_REF",
78 "GITHUB_REF_NAME",
79 "GITHUB_RUN_ATTEMPT",
80 "GITHUB_RUN_ID",
81 "GITHUB_RUN_NUMBER",
82 "RUNNER_ARCH",
83 "RUNNER_OS",
84 ]
85
86 # Add properties to the XML report
87 for name in include:
88 if name in os.environ:
89 xml.add_global_property(name, os.environ[name])

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected