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
This commit is contained in:
Commentator2.0
2025-05-22 13:51:23 +02:00
parent 5d49e26f71
commit 5daddad39a
2 changed files with 13 additions and 3 deletions
+6
View File
@@ -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"`
+7 -3
View File
@@ -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()