Skip to content

Commit 91e1577

Browse files
committed
🧪 test(fork): cover PID namespace identity
Windows cannot read /proc/self/ns/pid, so its coverage run missed the successful identity path. Test a readable stat result alongside the missing-path case on every platform. Refs #1021
1 parent e983ab7 commit 91e1577

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎tests/test_fork_ownership.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,21 @@ def namespace():
216216
assert (result.returncode, result.stderr) == (0, "")
217217

218218

219-
def test_pid_namespace_unavailable(mocker: MockerFixture) -> None:
219+
@pytest.mark.parametrize(
220+
("result", "expected"),
221+
[
222+
pytest.param(FileNotFoundError(), None, id="unavailable"),
223+
pytest.param(os.stat_result((0, 22, 11, 0, 0, 0, 0, 0, 0, 0)), (11, 22), id="available"),
224+
],
225+
)
226+
def test_pid_namespace_identity(
227+
mocker: MockerFixture, result: os.stat_result | OSError, expected: tuple[int, int] | None
228+
) -> None:
220229
from filelock import _api # simplint: ignore[import-outside-top-level] # tests the optional /proc fallback
221230

222-
mocker.patch("filelock._api.pathlib.Path.stat", side_effect=FileNotFoundError, autospec=True)
231+
mocker.patch("filelock._api.pathlib.Path.stat", side_effect=[result], autospec=True)
223232

224-
assert _api._pid_namespace() is None
233+
assert _api._pid_namespace() == expected
225234

226235

227236
@pytest.mark.requires_hard_links

0 commit comments

Comments
 (0)