6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00

Failed == assert of two strings now uses ndiff to report differences

This commit is contained in:
Pavel Císař 2023-11-08 17:51:28 +01:00
parent 1b08a7a67e
commit 7ed1bbd9ed
2 changed files with 12 additions and 1 deletions

View File

@ -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.

View File

@ -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