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

Code before:

        result = pytester.runpytest_inprocess(
            "--collect-only",
            "--keep-duplicates",
            "top1/test_1.py::test_3",
            "top1/test_1.py",
        )
        result.stdout.fnmatch_lines(
            [
                "<Dir *>",
                "  <Package top1>",
                # NOTE: That <Module test_1.py> is duplicated here is not great.
                "    <Module test_1.py>",
                "      <Function test_3>",
                "    <Module test_1.py>",
                "      <Function test_1>",
                "      <Class TestIt>",
                "        <Function test_2>",
                "      <Function test_3>",
                "",
            ],
            consecutive=True,
        )


class TestRequireUniqueParamsetIds:
    CASES = [
        ("[(1, 1), (1, 1)]", {"1-1": [0, 1]}),
        ("[(1, 1), (1, 2), (1, 1)]", {"1-1": [0, 2]}),
        ("[(1, 1), (2, 2), (1, 1)]", {"1-1": [0, 2]}),
        ("[(1, 1), (2, 2), (1, 2), (2, 1), (1, 1)]", {"1-1": [0, 4]}),
    ]

    @staticmethod
    def _fnmatch_escape_repr(obj) -> str:
        return re.sub(r"[*?[\]]", (lambda m: f"[{m.group()}]"), repr(obj))

    def _assert_duplicate_msg(self, result, expected_indices):
        stream = result.stdout
        stream.fnmatch_lines(
            [
                "When --require-unique-parameterization-ids set, pytest won't generate unique IDs for parameters.",
                "test name: *::test1",
                "argument names: [[]'y', 'x'[]]",
                f"duplicates: {self._fnmatch_escape_repr(expected_indices)}",
                "you must make sure all parameterization IDs are unique, either by:",
                "- providing unique IDs per parameterization via the ids=[...] argument to @pytest.mark.parametrize",
                "- providing a custom id function that generates unique IDs for each parameterization",
                "- not setting --require-unique-parameterization-ids",
            ]
        )

Review comment (suggestion):
```suggestion
class TestRequireUniqueParametrizationtIds:
```

Code after:

        result = pytester.runpytest_inprocess(
            "--collect-only",
            "--keep-duplicates",
            "top1/test_1.py::test_3",
            "top1/test_1.py",
        )
        result.stdout.fnmatch_lines(
            [
                "<Dir *>",
                "  <Package top1>",
                # NOTE: That <Module test_1.py> is duplicated here is not great.
                "    <Module test_1.py>",
                "      <Function test_3>",
                "    <Module test_1.py>",
                "      <Function test_1>",
                "      <Class TestIt>",
                "        <Function test_2>",
                "      <Function test_3>",
                "",
            ],
            consecutive=True,
        )


@pytest.mark.parametrize(
    ["x_y", "expected_duplicates"],
    [
        (
            [(1, 1), (1, 1)],
            ["1-1"],
        ),
        (
            [(1, 1), (1, 2), (1, 1)],
            ["1-1"],
        ),
        (
            [(1, 1), (2, 2), (1, 1)],
            ["1-1"],
        ),
        (
            [(1, 1), (2, 2), (1, 2), (2, 1), (1, 1), (2, 1)],
            ["1-1", "2-1"],
        ),
    ],
)
def test_strict_parametrization_ids(
    pytester: Pytester,
    x_y: Sequence[tuple[int, int]],
    expected_duplicates: Sequence[str],
) -> None: