@@ -284,7 +284,7 @@ def pytest_sessionstart(self, session):
284284 self .start (engine .Central )
285285
286286 if self .options .cov_context == 'test' :
287- session .config .pluginmanager .register (TestContextPlugin (self .cov_controller . cov ), '_cov_contexts' )
287+ session .config .pluginmanager .register (TestContextPlugin (self .cov_controller ), '_cov_contexts' )
288288
289289 @pytest .hookimpl (optionalhook = True )
290290 def pytest_configure_node (self , node ):
@@ -408,8 +408,10 @@ def pytest_runtest_call(self, item):
408408
409409
410410class TestContextPlugin :
411- def __init__ (self , cov ):
412- self .cov = cov
411+ cov_controller : 'CovController'
412+
413+ def __init__ (self , cov_controller ):
414+ self .cov_controller = cov_controller
413415
414416 def pytest_runtest_setup (self , item ):
415417 self .switch_context (item , 'setup' )
@@ -421,9 +423,10 @@ def pytest_runtest_call(self, item):
421423 self .switch_context (item , 'run' )
422424
423425 def switch_context (self , item , when ):
424- context = f'{ item .nodeid } |{ when } '
425- self .cov .switch_context (context )
426- os .environ ['COV_CORE_CONTEXT' ] = context
426+ if self .cov_controller .started :
427+ context = f'{ item .nodeid } |{ when } '
428+ self .cov_controller .cov .switch_context (context )
429+ os .environ ['COV_CORE_CONTEXT' ] = context
427430
428431
429432@pytest .fixture
0 commit comments