Skip to content

Commit

Permalink
test: fsinfo: set u+rwx on directories on teardown
Browse files Browse the repository at this point in the history
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
    <class 'OSError'>: [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).
  • Loading branch information
allisonkarlitskaya committed Aug 28, 2024
1 parent b209ba5 commit b9e161f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/pytest/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b9e161f

Please sign in to comment.