Merge pull request #6743 from bluetech/runtest-getattr
Avoid getattr when dispatching pytest_runtest_* hooks
This commit is contained in:
commit
959e6b4f44
|
@ -24,5 +24,6 @@ exclude_lines =
|
||||||
\#\s*pragma: no cover
|
\#\s*pragma: no cover
|
||||||
^\s*raise NotImplementedError\b
|
^\s*raise NotImplementedError\b
|
||||||
^\s*return NotImplemented\b
|
^\s*return NotImplemented\b
|
||||||
|
^\s*assert False(,|$)
|
||||||
|
|
||||||
^\s*if TYPE_CHECKING:
|
^\s*if TYPE_CHECKING:
|
||||||
|
|
|
@ -25,6 +25,7 @@ from _pytest.outcomes import TEST_OUTCOME
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
#
|
#
|
||||||
# pytest plugin hooks
|
# pytest plugin hooks
|
||||||
|
@ -181,7 +182,9 @@ def pytest_report_teststatus(report):
|
||||||
# Implementation
|
# Implementation
|
||||||
|
|
||||||
|
|
||||||
def call_and_report(item, when, log=True, **kwds):
|
def call_and_report(
|
||||||
|
item, when: "Literal['setup', 'call', 'teardown']", log=True, **kwds
|
||||||
|
):
|
||||||
call = call_runtest_hook(item, when, **kwds)
|
call = call_runtest_hook(item, when, **kwds)
|
||||||
hook = item.ihook
|
hook = item.ihook
|
||||||
report = hook.pytest_runtest_makereport(item=item, call=call)
|
report = hook.pytest_runtest_makereport(item=item, call=call)
|
||||||
|
@ -200,9 +203,15 @@ def check_interactive_exception(call, report):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def call_runtest_hook(item, when, **kwds):
|
def call_runtest_hook(item, when: "Literal['setup', 'call', 'teardown']", **kwds):
|
||||||
hookname = "pytest_runtest_" + when
|
if when == "setup":
|
||||||
ihook = getattr(item.ihook, hookname)
|
ihook = item.ihook.pytest_runtest_setup
|
||||||
|
elif when == "call":
|
||||||
|
ihook = item.ihook.pytest_runtest_call
|
||||||
|
elif when == "teardown":
|
||||||
|
ihook = item.ihook.pytest_runtest_teardown
|
||||||
|
else:
|
||||||
|
assert False, "Unhandled runtest hook case: {}".format(when)
|
||||||
reraise = (Exit,) # type: Tuple[Type[BaseException], ...]
|
reraise = (Exit,) # type: Tuple[Type[BaseException], ...]
|
||||||
if not item.config.getoption("usepdb", False):
|
if not item.config.getoption("usepdb", False):
|
||||||
reraise += (KeyboardInterrupt,)
|
reraise += (KeyboardInterrupt,)
|
||||||
|
|
Loading…
Reference in New Issue