File: utils.py

package info (click to toggle)
python-web-poet 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 908 kB
  • sloc: python: 6,112; makefile: 19
file content (25 lines) | stat: -rw-r--r-- 634 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from _pytest.assertion.util import assertrepr_compare

if TYPE_CHECKING:
    import pytest


def comparison_error_message(
    config: pytest.Config, op: str, expected: Any, got: Any, prefix: str = ""
) -> str:
    """Generate an error message"""
    lines = [prefix] if prefix else []

    explanation_lines = assertrepr_compare(
        config=config, op=op, left=got, right=expected
    )
    if explanation_lines:
        lines.extend(explanation_lines)
    else:
        lines.append(f"Expected: {expected!r}, got: {got!r}")

    return "\n".join(lines)