feat: Enhance JUnit XML reporting with environment variables and add import to conftest.py
What changed, and why it matters
This commit only changes test reporting code. It adds GitHub Actions environment variables to JUnit XML test reports and adds a missing `import os` statement. There is no change to Core Lightning's wallet, network, or node logic, and no security relevance.
No security action needed. This is a benign CI/test-infrastructure improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies two conftest.py files used by pytest. The root conftest.py gets a whitespace-only change. tests/conftest.py adds import os and a pytest_sessionfinish hook that, on the pytest-xdist master node, finds the JUnit XML plugin and calls add_global_property for a fixed list of GitHub Actions environment variables. No production code, cryptography, RPC, or network handling is touched.
Changed components
tests/conftest.pyconftest.pyInspect captured patch +49 / −0
diff --git a/conftest.py b/conftest.py
index 65b3e323..4f5bd3b9 100644
--- a/conftest.py
+++ b/conftest.py
@@ -8,6 +8,7 @@ import unittest
server = os.environ.get("CI_SERVER_URL", None)
+
github_sha = (
subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ASCII").strip()
)
diff --git a/tests/conftest.py b/tests/conftest.py
index dcbd43ca..bd0b7a30 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,4 +1,5 @@
import pytest
+import os
from pyln.testing.utils import EXPERIMENTAL_DUAL_FUND, VALGRIND, SLOW_MACHINE
@@ -39,3 +40,50 @@ def pytest_runtest_setup(item):
pytest.skip('v1-only test, EXPERIMENTAL_DUAL_FUND=1')
if "slow_test" in item.keywords and VALGRIND and SLOW_MACHINE:
pytest.skip("Skipping slow tests under VALGRIND")
+
+
+@pytest.hookimpl(tryfirst=True)
+def pytest_sessionfinish(session, exitstatus):
+ """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 the junitxml plugin writes the file.
+
+ See: https://github.com/pytest-dev/pytest/issues/7767
+ """
+ # Check if we're on the master node (not a worker)
+ # Workers have the workeroutput attribute
+ if hasattr(session.config, "workeroutput"):
+ return
+
+ # Find the LogXML instance among registered plugins
+ # We need to search through all plugins because it's not directly accessible
+ xml = None
+ for plugin in session.config.pluginmanager.get_plugins():
+ if hasattr(plugin, "add_global_property"):
+ xml = plugin
+ break
+
+ if xml is None:
+ return
+
+ # List of environment variables to include in the report
+ include = [
+ "GITHUB_ACTION_REPOSITORY",
+ "GITHUB_EVENT_NAME",
+ "GITHUB_HEAD_REF",
+ "GITHUB_REF_NAME",
+ "GITHUB_RUN_ATTEMPT",
+ "GITHUB_RUN_ID",
+ "GITHUB_RUN_NUMBER",
+ "RUNNER_ARCH",
+ "RUNNER_OS",
+ ]
+
+ # Add properties to the XML report
+ for name in include:
+ if name in os.environ:
+ xml.add_global_property(name, os.environ[name])
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.