Skip to content

Commit 992a7a8

Browse files
authored
Merge pull request #7397 from lgeiger/reduce-ihook-calls
Reduce calls to item.ihook
2 parents 7450b6d + 97d2c71 commit 992a7a8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/_pytest/assertion/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def pytest_runtest_protocol(item: Item) -> Generator[None, None, None]:
124124
comparison for the test.
125125
"""
126126

127+
ihook = item.ihook
128+
127129
def callbinrepr(op, left: object, right: object) -> Optional[str]:
128130
"""Call the pytest_assertrepr_compare hook and prepare the result
129131
@@ -139,7 +141,7 @@ def callbinrepr(op, left: object, right: object) -> Optional[str]:
139141
The result can be formatted by util.format_explanation() for
140142
pretty printing.
141143
"""
142-
hook_result = item.ihook.pytest_assertrepr_compare(
144+
hook_result = ihook.pytest_assertrepr_compare(
143145
config=item.config, op=op, left=left, right=right
144146
)
145147
for new_expl in hook_result:
@@ -155,12 +157,10 @@ def callbinrepr(op, left: object, right: object) -> Optional[str]:
155157
saved_assert_hooks = util._reprcompare, util._assertion_pass
156158
util._reprcompare = callbinrepr
157159

158-
if item.ihook.pytest_assertion_pass.get_hookimpls():
160+
if ihook.pytest_assertion_pass.get_hookimpls():
159161

160162
def call_assertion_pass_hook(lineno: int, orig: str, expl: str) -> None:
161-
item.ihook.pytest_assertion_pass(
162-
item=item, lineno=lineno, orig=orig, expl=expl
163-
)
163+
ihook.pytest_assertion_pass(item=item, lineno=lineno, orig=orig, expl=expl)
164164

165165
util._assertion_pass = call_assertion_pass_hook
166166

src/_pytest/runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ def pytest_sessionfinish(session: "Session") -> None:
9595

9696

9797
def pytest_runtest_protocol(item: Item, nextitem: Optional[Item]) -> bool:
98-
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
98+
ihook = item.ihook
99+
ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
99100
runtestprotocol(item, nextitem=nextitem)
100-
item.ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
101+
ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
101102
return True
102103

103104

0 commit comments

Comments
 (0)