From f187508595c804b43405b8a742357a19fc3e3694 Mon Sep 17 00:00:00 2001 From: Raphael Bizos Date: Wed, 28 Oct 2026 17:02:18 +0100 Subject: [PATCH] Skip the parser benchmark when pytest-benchmark is incompatible pytest 9.2 removed Node._nodeid, which pytest-benchmark 5.3.0 and older still read (ionelmc/pytest-benchmark#321), so the benchmark test errors at setup. Skip it in that case; it runs again once pytest-benchmark releases a fix. Signed-off-by: Raphael Bizos Co-Authored-By: Claude Opus 5.5 --- tests/test_parser.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_parser.py b/tests/test_parser.py index 8436dd0c..c400ce52 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,7 +1,10 @@ +import importlib.metadata import importlib.util import math import unittest +import pytest + from prometheus_client.core import ( CollectorRegistry, CounterMetricFamily, GaugeMetricFamily, HistogramMetricFamily, Metric, Sample, SummaryMetricFamily, @@ -378,7 +381,20 @@ def collect(self): HAS_BENCHMARK = importlib.util.find_spec("pytest_benchmark") is not None + +def _benchmark_compatible_with_pytest(): + # pytest-benchmark 5.3.0 and older read Node._nodeid, which pytest 9.2 + # removed: https://github.com/ionelmc/pytest-benchmark/issues/321 + from _pytest.nodes import Node + from packaging.version import Version + if hasattr(Node, '_nodeid'): + return True + return Version(importlib.metadata.version('pytest-benchmark')) > Version('5.3.0') + + if HAS_BENCHMARK: + @pytest.mark.skipif(not _benchmark_compatible_with_pytest(), + reason='pytest-benchmark is not compatible with this pytest version') def test_benchmark_text_string_to_metric_families(benchmark): text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary