Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/_pytest/assertion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
support for presenting detailed information in failing assertions.
"""
import sys
from typing import Any
from typing import List
from typing import Optional

from _pytest.assertion import rewrite
from _pytest.assertion import truncate
from _pytest.assertion import util
from _pytest.compat import TYPE_CHECKING
from _pytest.config import Config
from _pytest.config import hookimpl

if TYPE_CHECKING:
Expand Down Expand Up @@ -169,5 +172,7 @@ def pytest_sessionfinish(session):
assertstate.hook.set_session(None)


def pytest_assertrepr_compare(config, op, left, right):
def pytest_assertrepr_compare(
config: Config, op: str, left: Any, right: Any
) -> Optional[List[str]]:
return util.assertrepr_compare(config=config, op=op, left=left, right=right)
22 changes: 16 additions & 6 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import collections.abc as collections_abc
import sys
import textwrap
from typing import Any
from typing import List
from typing import Optional

import attr

Expand Down Expand Up @@ -310,9 +313,13 @@ def test_check(list):
result.stdout.fnmatch_lines(["*test_hello*FAIL*", "*test_check*PASS*"])


def callequal(left, right, verbose=0):
def callop(op: str, left: Any, right: Any, verbose: int = 0) -> Optional[List[str]]:
config = mock_config(verbose=verbose)
return plugin.pytest_assertrepr_compare(config, "==", left, right)
return plugin.pytest_assertrepr_compare(config, op, left, right)


def callequal(left: Any, right: Any, verbose: int = 0) -> Optional[List[str]]:
return callop("==", left, right, verbose)


class TestAssert_reprcompare:
Expand Down Expand Up @@ -1067,10 +1074,13 @@ def test_rewritten():
assert testdir.runpytest().ret == 0


def test_reprcompare_notin():
config = mock_config()
detail = plugin.pytest_assertrepr_compare(config, "not in", "foo", "aaafoobbb")[1:]
assert detail == ["'foo' is contained here:", " aaafoobbb", "? +++"]
def test_reprcompare_notin() -> None:
assert callop("not in", "foo", "aaafoobbb") == [
"'foo' not in 'aaafoobbb'",
"'foo' is contained here:",
" aaafoobbb",
"? +++",
]


def test_reprcompare_whitespaces():
Expand Down