From 5daddad39a99c38bd160d0c4f729087caa52d145 Mon Sep 17 00:00:00 2001 From: "Commentator2.0" Date: Wed, 21 May 2025 20:06:57 +0200 Subject: [PATCH] tests/functional2: Fix pytest garbage collection Due to nix-store making its paths read-only, pytest was unable to remove the test files and hence the entire temporary directory, screaming all over the place in stderr about that, getting worse for each test run. By making the nix fixture first yield nix and then, after the test finished running, changing the file permissions to include read on all files and directories within the temp folder, pytest is able to properly remove old test runs again Additionally added more clear instructions for file deletion to the pytest configuration Change-Id: Ia7e3d195665968ac80a57d0e525691b28be7f503 --- tests/functional2/pyproject.toml | 6 ++++++ tests/functional2/testlib/fixtures/nix.py | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/functional2/pyproject.toml b/tests/functional2/pyproject.toml index d807b996e..2c8a2122c 100644 --- a/tests/functional2/pyproject.toml +++ b/tests/functional2/pyproject.toml @@ -5,6 +5,12 @@ requires-python = ">=3.11" [tool.pytest.ini_options] addopts = "-p no:xonsh" + +# Keep the temporary files of the last 3 test runs (default value) +tmp_path_retention_count = 3 +# Keep temporary files of all tests, regardless if they failed or not +tmp_path_retention_policy = "all" + log_cli = true log_cli_level = "INFO" # how the logs are being printed, default is `"%(filename)s %(lineno)d %(levelname)s %(message)s"` diff --git a/tests/functional2/testlib/fixtures/nix.py b/tests/functional2/testlib/fixtures/nix.py index c893c76e2..63ce1d176 100644 --- a/tests/functional2/testlib/fixtures/nix.py +++ b/tests/functional2/testlib/fixtures/nix.py @@ -6,7 +6,7 @@ import subprocess from functools import partialmethod from pathlib import Path from typing import Any, AnyStr -from collections.abc import Callable +from collections.abc import Callable, Generator import pytest @@ -239,5 +239,9 @@ class Nix: @pytest.fixture -def nix(tmp_path: Path) -> Nix: - return Nix(tmp_path) +def nix(tmp_path: Path) -> Generator[Nix, Any, None]: + yield Nix(tmp_path) + # when things are done using the nix store, the permissions for the store are read only + # after the test was executed, we set the permissions to rwx (write being the important part) + # for pytest to be able to delete the files during cleanup + Command(argv=["chmod", "-R", "+w", str(tmp_path.absolute())], env=os.environ.copy()).run().ok()