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 weakref
|
||||||
import pytest
|
import pytest
|
||||||
from configparser import ConfigParser, ExtendedInterpolation
|
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.terminal import TerminalReporter, _get_raw_skip_reason, _format_trimmed
|
||||||
from _pytest.pathlib import bestrelpath
|
from _pytest.pathlib import bestrelpath
|
||||||
from subprocess import run, CompletedProcess, PIPE, STDOUT
|
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(("description", item._qa_description_))
|
||||||
item.user_properties.append(("notes", item._qa_notes_))
|
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]):
|
def substitute_macros(text: str, macros: Dict[str, str]):
|
||||||
"""Helper function to substitute `$(name)` macros in text.
|
"""Helper function to substitute `$(name)` macros in text.
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ all-files=True
|
|||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
name = firebird-qa
|
name = firebird-qa
|
||||||
version = 0.18.0
|
version = 0.19.0
|
||||||
description = pytest plugin for Firebird QA
|
description = pytest plugin for Firebird QA
|
||||||
long_description = file: README.rst
|
long_description = file: README.rst
|
||||||
long_description_content_type = text/x-rst; charset=UTF-8
|
long_description_content_type = text/x-rst; charset=UTF-8
|
||||||
|
Loading…
Reference in New Issue
Block a user