runner: inline `call_runtest_hook`
- Reduce the common stacktrace by an entry - this is mostly for benefit of devs looking at crash logs. - Reduce 6 slow `ihook` calls per test to 3.
This commit is contained in:
parent
c3fc717ff7
commit
5ab8972bb5
|
@ -223,13 +223,26 @@ def pytest_report_teststatus(report: BaseReport) -> Optional[Tuple[str, str, str
|
||||||
def call_and_report(
|
def call_and_report(
|
||||||
item: Item, when: Literal["setup", "call", "teardown"], log: bool = True, **kwds
|
item: Item, when: Literal["setup", "call", "teardown"], log: bool = True, **kwds
|
||||||
) -> TestReport:
|
) -> TestReport:
|
||||||
call = call_runtest_hook(item, when, **kwds)
|
ihook = item.ihook
|
||||||
hook = item.ihook
|
if when == "setup":
|
||||||
report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
|
runtest_hook: Callable[..., None] = ihook.pytest_runtest_setup
|
||||||
|
elif when == "call":
|
||||||
|
runtest_hook = ihook.pytest_runtest_call
|
||||||
|
elif when == "teardown":
|
||||||
|
runtest_hook = ihook.pytest_runtest_teardown
|
||||||
|
else:
|
||||||
|
assert False, f"Unhandled runtest hook case: {when}"
|
||||||
|
reraise: Tuple[Type[BaseException], ...] = (Exit,)
|
||||||
|
if not item.config.getoption("usepdb", False):
|
||||||
|
reraise += (KeyboardInterrupt,)
|
||||||
|
call = CallInfo.from_call(
|
||||||
|
lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
|
||||||
|
)
|
||||||
|
report: TestReport = ihook.pytest_runtest_makereport(item=item, call=call)
|
||||||
if log:
|
if log:
|
||||||
hook.pytest_runtest_logreport(report=report)
|
ihook.pytest_runtest_logreport(report=report)
|
||||||
if check_interactive_exception(call, report):
|
if check_interactive_exception(call, report):
|
||||||
hook.pytest_exception_interact(node=item, call=call, report=report)
|
ihook.pytest_exception_interact(node=item, call=call, report=report)
|
||||||
return report
|
return report
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,25 +261,6 @@ def check_interactive_exception(call: "CallInfo[object]", report: BaseReport) ->
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def call_runtest_hook(
|
|
||||||
item: Item, when: Literal["setup", "call", "teardown"], **kwds
|
|
||||||
) -> "CallInfo[None]":
|
|
||||||
if when == "setup":
|
|
||||||
ihook: Callable[..., None] = 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, f"Unhandled runtest hook case: {when}"
|
|
||||||
reraise: Tuple[Type[BaseException], ...] = (Exit,)
|
|
||||||
if not item.config.getoption("usepdb", False):
|
|
||||||
reraise += (KeyboardInterrupt,)
|
|
||||||
return CallInfo.from_call(
|
|
||||||
lambda: ihook(item=item, **kwds), when=when, reraise=reraise
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
TResult = TypeVar("TResult", covariant=True)
|
TResult = TypeVar("TResult", covariant=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue