Skip to content

Commit 3101c02

Browse files
[flake8-bugbear] Remove hidden global state to import only once
1 parent e193a26 commit 3101c02

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ select = [
141141
ignore = [
142142
# bugbear ignore
143143
"B004", # Using `hasattr(x, "__call__")` to test if x is callable is unreliable.
144-
"B006", # Do not use mutable data structures for argument defaults
145144
"B007", # Loop control variable `i` not used within loop body
146145
"B009", # Do not call `getattr` with a constant attribute value
147146
"B010", # [*] Do not call `setattr` with a constant attribute value.

src/_pytest/unittest.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
367368
def 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-
409406
def _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

Comments
 (0)