Merge pull request #7397 from lgeiger/reduce-ihook-calls

Reduce calls to item.ihook
This commit is contained in:
Ran Benita 2020-06-28 15:01:43 +03:00 committed by GitHub
commit 992a7a8d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -124,6 +124,8 @@ def pytest_runtest_protocol(item: Item) -> Generator[None, None, None]:
comparison for the test. comparison for the test.
""" """
ihook = item.ihook
def callbinrepr(op, left: object, right: object) -> Optional[str]: def callbinrepr(op, left: object, right: object) -> Optional[str]:
"""Call the pytest_assertrepr_compare hook and prepare the result """Call the pytest_assertrepr_compare hook and prepare the result
@ -139,7 +141,7 @@ def pytest_runtest_protocol(item: Item) -> Generator[None, None, None]:
The result can be formatted by util.format_explanation() for The result can be formatted by util.format_explanation() for
pretty printing. pretty printing.
""" """
hook_result = item.ihook.pytest_assertrepr_compare( hook_result = ihook.pytest_assertrepr_compare(
config=item.config, op=op, left=left, right=right config=item.config, op=op, left=left, right=right
) )
for new_expl in hook_result: for new_expl in hook_result:
@ -155,12 +157,10 @@ def pytest_runtest_protocol(item: Item) -> Generator[None, None, None]:
saved_assert_hooks = util._reprcompare, util._assertion_pass saved_assert_hooks = util._reprcompare, util._assertion_pass
util._reprcompare = callbinrepr util._reprcompare = callbinrepr
if item.ihook.pytest_assertion_pass.get_hookimpls(): if ihook.pytest_assertion_pass.get_hookimpls():
def call_assertion_pass_hook(lineno: int, orig: str, expl: str) -> None: def call_assertion_pass_hook(lineno: int, orig: str, expl: str) -> None:
item.ihook.pytest_assertion_pass( ihook.pytest_assertion_pass(item=item, lineno=lineno, orig=orig, expl=expl)
item=item, lineno=lineno, orig=orig, expl=expl
)
util._assertion_pass = call_assertion_pass_hook util._assertion_pass = call_assertion_pass_hook

View File

@ -95,9 +95,10 @@ def pytest_sessionfinish(session: "Session") -> None:
def pytest_runtest_protocol(item: Item, nextitem: Optional[Item]) -> bool: def pytest_runtest_protocol(item: Item, nextitem: Optional[Item]) -> bool:
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location) ihook = item.ihook
ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
runtestprotocol(item, nextitem=nextitem) runtestprotocol(item, nextitem=nextitem)
item.ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location) ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
return True return True