diff --git a/firebird/qa/plugin.py b/firebird/qa/plugin.py index 226b9a2d..d61bf805 100644 --- a/firebird/qa/plugin.py +++ b/firebird/qa/plugin.py @@ -47,6 +47,8 @@ import platform import weakref import pytest from configparser import ConfigParser, ExtendedInterpolation +from difflib import ndiff +from _pytest.config import Config from _pytest.terminal import TerminalReporter, _get_raw_skip_reason, _format_trimmed from _pytest.pathlib import bestrelpath from subprocess import run, CompletedProcess, PIPE, STDOUT @@ -570,6 +572,15 @@ def pytest_collection_modifyitems(session, config, items): item.user_properties.append(("description", item._qa_description_)) item.user_properties.append(("notes", item._qa_notes_)) +def pytest_assertrepr_compare(config: Config, op: str, left: object, right: object) -> Optional[List[str]]: + """Returns explanation for comparisons in failing assert expressions. + + If both objects are `str`, uses `difflib.ndiff` to provide explanation. + """ + if isinstance(left, str) and isinstance(right, str) and op == "==": + return ndiff(left.splitlines(), right.splitlines()) + return None + def substitute_macros(text: str, macros: Dict[str, str]): """Helper function to substitute `$(name)` macros in text. diff --git a/setup.cfg b/setup.cfg index 4eca44ed..54f9b06b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,7 +5,7 @@ all-files=True [metadata] name = firebird-qa -version = 0.18.0 +version = 0.19.0 description = pytest plugin for Firebird QA long_description = file: README.rst long_description_content_type = text/x-rst; charset=UTF-8