Add session-scoped topology fixture in tests/conftest.py
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user