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
This commit is contained in:
Commentator2.0
2025-10-13 14:33:25 +00:00
committed by Rutile
parent 2e3d97eb37
commit 844feb17b5
2 changed files with 27 additions and 0 deletions
+7
View File
@@ -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:
+20
View File
@@ -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()