Skip to content

Commit 198b765

Browse files
committed
assertion: push config access up from assertrepr_compare to the hook
Seems better to make the lower-level function more agnostic.
1 parent 537086a commit 198b765

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/_pytest/assertion/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,11 @@ def pytest_sessionfinish(session: Session) -> None:
205205
def pytest_assertrepr_compare(
206206
config: Config, op: str, left: Any, right: Any
207207
) -> list[str] | None:
208-
return util.assertrepr_compare(config=config, op=op, left=left, right=right)
208+
highlighter = config.get_terminal_writer()._highlight
209+
return util.assertrepr_compare(
210+
op=op,
211+
left=left,
212+
right=right,
213+
verbose=config.get_verbosity(Config.VERBOSITY_ASSERTIONS),
214+
highlighter=highlighter,
215+
)

src/_pytest/assertion/util.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,14 @@ def has_default_eq(obj: object) -> bool:
174174

175175

176176
def assertrepr_compare(
177-
config: Config, op: str, left: object, right: object
177+
op: str,
178+
left: object,
179+
right: object,
180+
*,
181+
verbose: int,
182+
highlighter: _HighlightFunc,
178183
) -> list[str] | None:
179184
"""Return specialised explanations for some operators/operands."""
180-
verbose = config.get_verbosity(Config.VERBOSITY_ASSERTIONS)
181-
182185
# Strings which normalize equal are often hard to distinguish when printed; use ascii() to make this easier.
183186
# See issue #3246.
184187
use_ascii = (
@@ -201,7 +204,6 @@ def assertrepr_compare(
201204
right_repr = saferepr(right, maxsize=maxsize, use_ascii=use_ascii)
202205

203206
summary = f"{left_repr} {op} {right_repr}"
204-
highlighter = config.get_terminal_writer()._highlight
205207

206208
explanation = None
207209
try:

0 commit comments

Comments
 (0)