diff --git a/tests/functional2/lang/lang_util.py b/tests/functional2/lang/lang_util.py index 66a5f6718..7302ab2e9 100644 --- a/tests/functional2/lang/lang_util.py +++ b/tests/functional2/lang/lang_util.py @@ -346,6 +346,7 @@ def _collect_generic_test_group(folder: Path) -> tuple[list[LangTest], list[Inva invalid_tests: list[InvalidLangTest] = [] all_files = set(folder.iterdir()) unused = {f.name for f in all_files if not f.name.startswith("_")} + collected: set[str] = set() for file in all_files: file: Path if file.suffix == ".exp": @@ -356,6 +357,12 @@ def _collect_generic_test_group(folder: Path) -> tuple[list[LangTest], list[Inva # `"parse-fail-some-name.err.exp".stem` => "parse-fail-some-name.err" # `"parse-fail-some-name.err.exp".split(".")[0]` => "parse-fail-some-name" test_name = file.name.rsplit(".", 2)[0] + if test_name in collected: + # Skipping collection to avoid duplicate collection + # when both `.err.exp` and `.out.exp` are provided + # in case of non-error traces + continue + collected |= {test_name} full_name = LANG_TEST_ID_PATTERN.format(folder_name=parent_name, test_name=test_name) match = re.fullmatch(NAME_PATTERN_GENERIC_EXP, test_name) if match is None: diff --git a/tests/functional2/lang/test_lang_infra.py b/tests/functional2/lang/test_lang_infra.py index bf0a2816a..82f1bc73c 100644 --- a/tests/functional2/lang/test_lang_infra.py +++ b/tests/functional2/lang/test_lang_infra.py @@ -839,3 +839,23 @@ def test_generic_missing_in_file(pytest_command: Command): res = pytest_command.run().expect(1) out = res.stdout_plain assert "ERROR lang/test_lang.py::test_eval[generic-missing:eval-okay] - FileNotFound" in out + + +@pytest.mark.parametrize("pytest_command", [["--setup-plan"]], indirect=True) +@with_files( + get_functional2_lang_files( + { + "functional2": { + "lang": { + "generic-duplicate": { + "eval-okay.out.exp": File("A"), + "eval-okay.err.exp": File("B"), + "in.nix": File(""), + } + } + } + } + ) +) +def test_generic_no_duplicate_collection(pytest_command: Command): + pytest_command.run().ok()