@@ -209,8 +209,8 @@ def _addexcinfo(self, rawexcinfo: "_SysExcInfoType") -> None:
209209 )
210210 # Invoke the attributes to trigger storing the traceback
211211 # trial causes some issue there.
212- excinfo .value
213- excinfo .traceback
212+ _ = excinfo .value
213+ _ = excinfo .traceback
214214 except TypeError :
215215 try :
216216 try :
@@ -361,14 +361,21 @@ def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None:
361361
362362
363363# Twisted trial support.
364+ classImplements_has_run = False
364365
365366
366367@hookimpl (wrapper = True )
367368def pytest_runtest_protocol (item : Item ) -> Generator [None , object , object ]:
368369 if isinstance (item , TestCaseFunction ) and "twisted.trial.unittest" in sys .modules :
369370 ut : Any = sys .modules ["twisted.python.failure" ]
371+ global classImplements_has_run
370372 Failure__init__ = ut .Failure .__init__
371- check_testcase_implements_trial_reporter ()
373+ if not classImplements_has_run :
374+ from twisted .trial .itrial import IReporter
375+ from zope .interface import classImplements
376+
377+ classImplements (TestCaseFunction , IReporter )
378+ classImplements_has_run = True
372379
373380 def excstore (
374381 self , exc_value = None , exc_type = None , exc_tb = None , captureVars = None
@@ -396,16 +403,6 @@ def excstore(
396403 return res
397404
398405
399- def check_testcase_implements_trial_reporter (done : List [int ] = []) -> None :
400- if done :
401- return
402- from twisted .trial .itrial import IReporter
403- from zope .interface import classImplements
404-
405- classImplements (TestCaseFunction , IReporter )
406- done .append (1 )
407-
408-
409406def _is_skipped (obj ) -> bool :
410407 """Return True if the given object has been marked with @unittest.skip."""
411408 return bool (getattr (obj , "__unittest_skip__" , False ))
0 commit comments