[flake8-bugbear] Remove hidden global state to import only once
This commit is contained in:
parent
e193a263c7
commit
3101c026b9
|
@ -141,7 +141,6 @@ select = [
|
|||
ignore = [
|
||||
# bugbear ignore
|
||||
"B004", # Using `hasattr(x, "__call__")` to test if x is callable is unreliable.
|
||||
"B006", # Do not use mutable data structures for argument defaults
|
||||
"B007", # Loop control variable `i` not used within loop body
|
||||
"B009", # Do not call `getattr` with a constant attribute value
|
||||
"B010", # [*] Do not call `setattr` with a constant attribute value.
|
||||
|
|
|
@ -361,14 +361,21 @@ def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None:
|
|||
|
||||
|
||||
# Twisted trial support.
|
||||
classImplements_has_run = False
|
||||
|
||||
|
||||
@hookimpl(wrapper=True)
|
||||
def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]:
|
||||
if isinstance(item, TestCaseFunction) and "twisted.trial.unittest" in sys.modules:
|
||||
ut: Any = sys.modules["twisted.python.failure"]
|
||||
global classImplements_has_run
|
||||
Failure__init__ = ut.Failure.__init__
|
||||
check_testcase_implements_trial_reporter()
|
||||
if not classImplements_has_run:
|
||||
from twisted.trial.itrial import IReporter
|
||||
from zope.interface import classImplements
|
||||
|
||||
classImplements(TestCaseFunction, IReporter)
|
||||
classImplements_has_run = True
|
||||
|
||||
def excstore(
|
||||
self, exc_value=None, exc_type=None, exc_tb=None, captureVars=None
|
||||
|
@ -396,16 +403,6 @@ def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]:
|
|||
return res
|
||||
|
||||
|
||||
def check_testcase_implements_trial_reporter(done: List[int] = []) -> None:
|
||||
if done:
|
||||
return
|
||||
from twisted.trial.itrial import IReporter
|
||||
from zope.interface import classImplements
|
||||
|
||||
classImplements(TestCaseFunction, IReporter)
|
||||
done.append(1)
|
||||
|
||||
|
||||
def _is_skipped(obj) -> bool:
|
||||
"""Return True if the given object has been marked with @unittest.skip."""
|
||||
return bool(getattr(obj, "__unittest_skip__", False))
|
||||
|
|
Loading…
Reference in New Issue