|
5 | 5 | from pathlib import Path
|
6 | 6 | from pathlib import PurePath
|
7 | 7 | import pprint
|
| 8 | +import re |
8 | 9 | import shutil
|
9 | 10 | import sys
|
10 | 11 | import tempfile
|
@@ -2031,3 +2032,40 @@ def test_namespace_packages(pytester: Pytester, import_mode: str):
|
2031 | 2032 | " <Function test_module3>",
|
2032 | 2033 | ]
|
2033 | 2034 | )
|
| 2035 | + |
| 2036 | + |
| 2037 | +@pytest.mark.parametrize( |
| 2038 | + "parametrize_args, expected_indexs", |
| 2039 | + [ |
| 2040 | + ("[(1, 1), (1, 1)]", {"1-1": [0, 1]}), |
| 2041 | + ("[(1, 1), (1, 2), (1, 1)]", {"1-1": [0, 2]}), |
| 2042 | + ("[(1, 1), (2, 2), (1, 1)]", {"1-1": [0, 2]}), |
| 2043 | + ("[(1, 1), (2, 2), (1, 2), (2, 1), (1, 1)]", {"1-1": [0, 4]}), |
| 2044 | + ], |
| 2045 | +) |
| 2046 | +def test_option_parametrize_require_unique_paramset_ids( |
| 2047 | + pytester: Pytester, parametrize_args, expected_indexs |
| 2048 | +) -> None: |
| 2049 | + pytester.makepyfile( |
| 2050 | + f""" |
| 2051 | + import pytest |
| 2052 | + @pytest.mark.parametrize('y, x', {parametrize_args}) |
| 2053 | + def test1(y, x): |
| 2054 | + pass |
| 2055 | + """ |
| 2056 | + ) |
| 2057 | + result = pytester.runpytest("--require-unique-paramset-ids") |
| 2058 | + result.stdout.fnmatch_lines( |
| 2059 | + [ |
| 2060 | + "E*Because: require_unique_parameterset_ids is set, pytest won't", |
| 2061 | + "E*attempt to generate unique IDs for parameter sets.", |
| 2062 | + "E*argument names: [[]'y', 'x'[]]", |
| 2063 | + "E*function name: test1", |
| 2064 | + "E*test name: test_option_parametrize_require_unique_paramset_ids.py::test1", |
| 2065 | + f"E*duplicates: {fnmatch_escape_repr(expected_indexs)}", |
| 2066 | + ] |
| 2067 | + ) |
| 2068 | + |
| 2069 | + |
| 2070 | +def fnmatch_escape_repr(obj): |
| 2071 | + return re.sub(r"[*?[\]]", (lambda m: f"[{m.group()}]"), repr(obj)) |
0 commit comments