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:
parent
1b08a7a67e
commit
7ed1bbd9ed
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user