From b9e161f26348265b57ac1b9fb2bf44147fb5b55c Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Wed, 28 Aug 2024 13:13:55 +0200 Subject: [PATCH] test: fsinfo: set u+rwx on directories on teardown We have a fixture which creates a bunch of testcases for unit testing fsinfo, including cases where we don't have access to access directories. This prevents pytest's tmpdir pruning from cleaning up after the test. Make sure we set mode 0777 on all directories after we're done. This takes care of the pile of warnings like warnings.warn( /usr/lib/python3.12/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-lis/garbage-1fa620ed-1fff-4854-aa93-d6a13d1567e3 : [Errno 39] Directory not empty: '/tmp/pytest-of-lis/garbage-1fa620ed-1fff-4854-aa93-d6a13d1567e3' that you otherwise get after a few runs of the test (once pytest start trying to prune the tmpdir of the older runs). --- test/pytest/test_bridge.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/pytest/test_bridge.py b/test/pytest/test_bridge.py index b4b02d78ca4b..b285fb022328 100644 --- a/test/pytest/test_bridge.py +++ b/test/pytest/test_bridge.py @@ -14,7 +14,7 @@ import unittest.mock from collections import deque from pathlib import Path -from typing import Dict, Iterable, Sequence +from typing import Dict, Iterable, Iterator, Sequence import pytest @@ -1010,7 +1010,7 @@ def fsinfo_err(err: int) -> JsonObject: @pytest.fixture -def fsinfo_test_cases(tmp_path: Path) -> 'dict[Path, JsonObject]': +def fsinfo_test_cases(tmp_path: Path) -> 'Iterator[dict[Path, JsonObject]]': # a normal directory normal_dir = tmp_path / 'dir' normal_dir.mkdir() @@ -1081,7 +1081,15 @@ def fsinfo_test_cases(tmp_path: Path) -> 'dict[Path, JsonObject]': del expected_state[no_r_dir] del expected_state[no_r_file] - return expected_state + try: + yield expected_state + + finally: + # restore writable permissions on directories. pytest has trouble cleaning + # these up, otherwise... + for path in expected_state: + if not path.is_symlink() and path.is_dir(): + path.chmod(0o700) @pytest.mark.asyncio