From 844feb17b562b7b9b59e73e35b73a05f8a531313 Mon Sep 17 00:00:00 2001 From: "Commentator2.0" Date: Sun, 12 Oct 2025 21:50:59 +0200 Subject: [PATCH] tests/functional2/lang: fix duplicate collection when both err and out are provided When providing both a `.err.exp` and a `.out.exp` for a lang test **not** containing a toml, the test was collected twice and hence threw a duplicate id error. This commit adresses this issue Change-Id: Ia781d69e0f1db2809a30192d6cd0a98861e6cc32 --- tests/functional2/lang/lang_util.py | 7 +++++++ tests/functional2/lang/test_lang_infra.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) 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()