mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 02:24:12 +01:00
35 lines
1.2 KiB
Python
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")
|