Repository: pytest-dev/pytest
File: testing/python/approx.py (Python)

Code before:

    def test_approx_on_unordered_mapping_with_mismatch(
        self, pytester: Pytester
    ) -> None:
        """https://github.com/pytest-dev/pytest/issues/12444"""
        pytester.makepyfile(
            """
            import pytest

            def test_approx_on_unordered_mapping_with_mismatch():
                expected = {"a": 1, "b": 2, "c": 3, "d": 4}
                actual = {"d": 4, "c": 5, "a": 8, "b": 2}
                assert actual == pytest.approx(expected)
            """
        )
        result = pytester.runpytest()
        result.assert_outcomes(failed=1)
        result.stdout.fnmatch_lines(
            [
                "*comparison failed.**Mismatched elements: 2 / 4:*",
                "*Max absolute difference: 7*",
            ]
        )


class MyVec3:  # incomplete
    """sequence like"""

    _x: int
    _y: int
    _z: int

    def __init__(self, x: int, y: int, z: int):
        self._x, self._y, self._z = x, y, z

    def __repr__(self) -> str:
        return f"<MyVec3 {self._x} {self._y} {self._z}>"

    def __len__(self) -> int:
        return 3

    def __getitem__(self, key: int) -> int:
        if key == 0:
            return self._x
        if key == 1:
            return self._y
        if key == 2:
            return self._z
        raise IndexError(key)



Review comment (bug):
I wanted to push this change and merge, but did not get permission:

```suggestion
        result = pytester.runpytest()
        result.assert_outcomes(failed=1)
        result.stdout.fnmatch_lines(
            [
                "*comparison failed.**Mismatched elements: 2 / 4:*",
                "*Max absolute difference: 7*",
                "*Index | Obtained | Expected *",
                "* a * | 8 * | 1 *",
                "* c * | 5 * | 3 *",
            ]
        )

    def test_approx_on_unordered_mapping_matching(self, pytester: Pytester) -> None:
        """https://github.com/pytest-dev/pytest/issues/12444"""
        pytester.makepyfile(
            """
            import pytest

            def test_approx_on_unordered_mapping_matching():
                expected = {"a": 1, "b": 2, "c": 3, "d": 4}
                actual = {"d": 4, "c": 3, "a": 1, "b": 2}
                assert actual == pytest.approx(expected)
            """
        )
        result = pytester.runpytest()
        result.assert_outcomes(passed=1)
```


Could you apply that please?

Code after:

    def test_approx_on_unordered_mapping_with_mismatch(
        self, pytester: Pytester
    ) -> None:
        """https://github.com/pytest-dev/pytest/issues/12444"""
        pytester.makepyfile(
            """
            import pytest

            def test_approx_on_unordered_mapping_with_mismatch():
                expected = {"a": 1, "b": 2, "c": 3, "d": 4}
                actual = {"d": 4, "c": 5, "a": 8, "b": 2}
                assert actual == pytest.approx(expected)
            """
        )
        result = pytester.runpytest()
        result.assert_outcomes(failed=1)
        result.stdout.fnmatch_lines(
            [
                "*comparison failed.**Mismatched elements: 2 / 4:*",
                "*Max absolute difference: 7*",
                "*Index | Obtained | Expected *",
                "* a * | 8 * | 1 *",
                "* c * | 5 * | 3 *",
            ]
        )

    def test_approx_on_unordered_mapping_matching(self, pytester: Pytester) -> None:
        """https://github.com/pytest-dev/pytest/issues/12444"""
        pytester.makepyfile(
            """
            import pytest
            def test_approx_on_unordered_mapping_matching():
                expected = {"a": 1, "b": 2, "c": 3, "d": 4}
                actual = {"d": 4, "c": 3, "a": 1, "b": 2}
                assert actual == pytest.approx(expected)
            """
        )
        result = pytester.runpytest()
        result.assert_outcomes(passed=1)


class MyVec3:  # incomplete
    """sequence like"""

    _x: int
    _y: int
    _z: int

    def __init__(self, x: int, y: int, z: int):
        self._x, self._y, self._z = x, y, z