From 8bbd5e1d0df9c31b4d86ba07bc85beb952e42ccb Mon Sep 17 00:00:00 2001 From: "Commentator2.0" Date: Wed, 11 Jun 2025 20:24:29 +0200 Subject: [PATCH] tests/functional2: do not copy testlib tests to internal environment When testing specific internal functionallity while needing things from the testlib, so far, the tests for the testlib have always been copied too. To reduce the amount of additional program required when later making the env of the pytest_command declarative, and to not test the same tests a multitude of times (and potentially reaching infinite recursion) those tests will no longer be copied Change-Id: I36ec3824a21ed30f9b8ff19948031d1edbf6c76c --- tests/functional2/testlib/fixtures/file_helper.py | 8 ++++++-- tests/functional2/testlib/utils.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/functional2/testlib/fixtures/file_helper.py b/tests/functional2/testlib/fixtures/file_helper.py index 037ebaae8..040afa89c 100644 --- a/tests/functional2/testlib/fixtures/file_helper.py +++ b/tests/functional2/testlib/fixtures/file_helper.py @@ -2,6 +2,7 @@ import shutil from abc import ABC, abstractmethod from pathlib import Path from typing import Any +from collections.abc import Callable, Iterable import pytest @@ -67,16 +68,19 @@ class CopyFile(Fileish): class CopyTree(Fileish): - def __init__(self, tree_base: str | Path): + def __init__( + self, tree_base: str | Path, ignore: Callable[[str, list[str]], Iterable[str]] | None = None + ): """ Declares a folder as a copy of an existing folder :param tree_base: base folder of the tree being copied """ self.tree_base = tree_base + self.ignore = ignore def copy_to(self, path: Path, origin: Path): orig = self.tree_base if isinstance(self.tree_base, Path) else origin / self.tree_base - shutil.copytree(orig, path, dirs_exist_ok=True) + shutil.copytree(orig, path, dirs_exist_ok=True, ignore=self.ignore) class CopyTemplate(_ByContentFileish): diff --git a/tests/functional2/testlib/utils.py b/tests/functional2/testlib/utils.py index 737e8d9ad..7a8253673 100644 --- a/tests/functional2/testlib/utils.py +++ b/tests/functional2/testlib/utils.py @@ -55,16 +55,22 @@ def get_functional2_files(additional_files: FileDeclaration | None = None) -> Fi def get_functional2_files_with_testlib( - additional_files: FileDeclaration | None = None, + additional_files: FileDeclaration | None = None, no_tests: bool = True ) -> FileDeclaration: if additional_files is None: additional_files = {} + if no_tests: + + def ignore(_: Any, names: list[str]) -> list[str]: + return [name for name in names if name.startswith("test_")] + else: + ignore = None return get_functional2_files( merge_file_declaration( { "functional2": { "conftest.py": CopyFile(functional2_base_folder / "conftest.py"), - "testlib": CopyTree(functional2_base_folder / "testlib"), + "testlib": CopyTree(functional2_base_folder / "testlib", ignore=ignore), } }, additional_files,