From 74f5f5cf0881fc26498e8f7f0ed35aee31a9c61b Mon Sep 17 00:00:00 2001 From: Yangwook Kang Date: Sun, 12 Apr 2026 21:13:25 -0700 Subject: [PATCH] Add session-scoped topology fixture in tests/conftest.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provides a shared `topology` fixture that caches the parsed topology.yaml result per pytest-xdist worker session. Tests that build a GraphEngine can accept `topology` instead of calling resolve_topology("topology.yaml") repeatedly. Topology parsing costs ~32ms, so the practical saving per worker is modest (<1s across all tests). The fixture is mainly for architectural cleanliness — keeping the "parse once, build engine many" pattern explicit. Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/conftest.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..9eff856 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,36 @@ +"""Shared pytest fixtures for the kernbench test suite. + +Session-scoped topology caching: ``resolve_topology("topology.yaml")`` is +pure (no side effects), so we cache the result across all tests in a +worker process. Each test still builds its own ``GraphEngine`` (which is +stateful/SimPy-event-consuming and MUST NOT be shared). +""" +from __future__ import annotations + +import pytest + +from kernbench.topology.builder import resolve_topology + + +@pytest.fixture(scope="session") +def topology(): + """Session-scoped parsed topology (immutable graph + spec). + + Usage in tests:: + + def test_foo(topology): + engine = GraphEngine(topology.topology_obj, enable_data=True) + """ + return resolve_topology("topology.yaml") + + +@pytest.fixture(scope="session") +def topology_obj(topology): + """The TopologyGraph inside the handle (convenience shortcut).""" + return topology.topology_obj + + +@pytest.fixture(scope="session") +def spec(topology): + """Topology spec dict (convenience shortcut).""" + return topology.topology_obj.spec