Files
OBLITERATUS/scripts/release_partition_plugin.py

35 lines
1.2 KiB
Python

"""Record selected canonical node IDs and preserve them in pytest JUnit."""
from __future__ import annotations
import json
from pathlib import Path
def pytest_addoption(parser):
parser.addoption("--release-nodeids", type=Path, required=True)
def pytest_configure(config):
config.pluginmanager.register(CollectionRecorder(config), "release-collection-recorder")
class CollectionRecorder:
def __init__(self, config):
self.output = config.getoption("release_nodeids")
self.skipped = []
def pytest_collectreport(self, report):
if report.skipped:
self.skipped.append({"nodeid": report.nodeid, "reason": str(report.longrepr)})
def pytest_collection_finish(self, session):
# All selection hooks have completed; preserve skips separately from items.
nodes = {"core": [], "gloo": []}
for item in session.items:
kind = "gloo" if item.get_closest_marker("gloo") else "core"
nodes[kind].append(item.nodeid)
item.user_properties.append(("release_nodeid", item.nodeid))
self.output.write_text(json.dumps({
"schema_version": 1, "nodes": nodes, "collection_skips": self.skipped,
}, sort_keys=True), encoding="utf-8")