1818import pytest
1919from _pytest .fixtures import FixtureManager
2020
21+ from pytest_codspeed .utils import get_git_relative_uri
22+
2123from . import __version__
2224from ._wrapper import get_lib
2325
@@ -169,7 +171,12 @@ def pytest_collection_modifyitems(
169171
170172
171173def _run_with_instrumentation (
172- lib : "LibType" , nodeId : str , fn : Callable [..., Any ], * args , ** kwargs
174+ lib : "LibType" ,
175+ nodeId : str ,
176+ config : "pytest.Config" ,
177+ fn : Callable [..., Any ],
178+ * args ,
179+ ** kwargs ,
173180):
174181 is_gc_enabled = gc .isenabled ()
175182 if is_gc_enabled :
@@ -185,12 +192,12 @@ def __codspeed_root_frame__():
185192 if SUPPORTS_PERF_TRAMPOLINE :
186193 # Warmup CPython performance map cache
187194 __codspeed_root_frame__ ()
188-
189195 lib .zero_stats ()
190196 lib .start_instrumentation ()
191197 __codspeed_root_frame__ ()
192198 lib .stop_instrumentation ()
193- lib .dump_stats_at (f"{ nodeId } " .encode ("ascii" ))
199+ uri = get_git_relative_uri (nodeId , config .rootpath )
200+ lib .dump_stats_at (uri .encode ("ascii" ))
194201 if is_gc_enabled :
195202 gc .enable ()
196203
@@ -226,7 +233,9 @@ def pytest_runtest_protocol(item: "pytest.Item", nextitem: Union["pytest.Item",
226233 if setup_report .passed and not item .config .getoption ("setuponly" ):
227234 assert plugin .lib is not None
228235 runtest_call = pytest .CallInfo .from_call (
229- lambda : _run_with_instrumentation (plugin .lib , item .nodeid , item .runtest ),
236+ lambda : _run_with_instrumentation (
237+ plugin .lib , item .nodeid , item .config , item .runtest
238+ ),
230239 "call" ,
231240 )
232241 runtest_report = ihook .pytest_runtest_makereport (item = item , call = runtest_call )
@@ -257,12 +266,13 @@ def __init__(self, request: "pytest.FixtureRequest"):
257266 self ._request = request
258267
259268 def __call__ (self , func : Callable [..., T ], * args : Any , ** kwargs : Any ) -> T :
260- plugin = get_plugin (self ._request .config )
269+ config = self ._request .config
270+ plugin = get_plugin (config )
261271 plugin .benchmark_count += 1
262272 if plugin .is_codspeed_enabled and plugin .should_measure :
263273 assert plugin .lib is not None
264274 return _run_with_instrumentation (
265- plugin .lib , self ._request .node .nodeid , func , * args , ** kwargs
275+ plugin .lib , self ._request .node .nodeid , config , func , * args , ** kwargs
266276 )
267277 else :
268278 return func (* args , ** kwargs )
0 commit comments