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
This commit is contained in:
Commentator2.0
2025-08-07 14:25:51 +02:00
committed by Commentator2.0
parent a9117791e2
commit 8bbd5e1d0d
2 changed files with 14 additions and 4 deletions
@@ -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):
+8 -2
View File
@@ -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,