@@ -361,14 +361,21 @@ def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None:
361
361
362
362
363
363
# Twisted trial support.
364
+ classImplements_has_run = False
364
365
365
366
366
367
@hookimpl (wrapper = True )
367
368
def pytest_runtest_protocol (item : Item ) -> Generator [None , object , object ]:
368
369
if isinstance (item , TestCaseFunction ) and "twisted.trial.unittest" in sys .modules :
369
370
ut : Any = sys .modules ["twisted.python.failure" ]
371
+ global classImplements_has_run
370
372
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
372
379
373
380
def excstore (
374
381
self , exc_value = None , exc_type = None , exc_tb = None , captureVars = None
@@ -396,16 +403,6 @@ def excstore(
396
403
return res
397
404
398
405
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
-
409
406
def _is_skipped (obj ) -> bool :
410
407
"""Return True if the given object has been marked with @unittest.skip."""
411
408
return bool (getattr (obj , "__unittest_skip__" , False ))
0 commit comments