From 417c4864610ef7f14e2d3a4315a50d786b3395c7 Mon Sep 17 00:00:00 2001 From: rajashidattapy Date: Wed, 12 Aug 2026 00:15:24 +0530 Subject: [PATCH] test: skip the unreadable-dir detect test on non-POSIX platforms `test_detect_surfaces_unreadable_dir_instead_of_silent_skip` guards itself against running as root, because a `chmod 000` directory is still readable by root and the test would assert nothing. That guard calls `os.geteuid()`, which is Unix-only, so on Windows it raises AttributeError before the test can decide anything. Guard on the capability rather than shimming geteuid. A shim would only move the failure: Windows ignores POSIX mode bits, so `chmod 000` leaves the directory readable and the test then fails on its real assertion. Verified -- scandir on a chmod-000 directory succeeds and lists its contents there. The redundant function-local `import os` / `import pytest` go too; both are already module-level imports. Fixes #2643 --- tests/test_detect.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/test_detect.py b/tests/test_detect.py index 2c6cc177e..b367d306b 100644 --- a/tests/test_detect.py +++ b/tests/test_detect.py @@ -2518,14 +2518,24 @@ def test_detect_reports_walk_errors_key(): assert res["walk_errors"] == [] +@pytest.mark.skipif( + not hasattr(os, "geteuid"), + reason="POSIX-only: needs geteuid() and chmod 000 to actually block scandir", +) def test_detect_surfaces_unreadable_dir_instead_of_silent_skip(tmp_path, capsys): """os.walk silently skips a subtree whose scandir raises (permissions, or a dir deleted mid-walk); that under-enumeration used to be invisible and could yield a silently partial graph. detect() now records it in walk_errors and - warns, while still enumerating the rest of the tree.""" - import os + warns, while still enumerating the rest of the tree. + + Guarded on the capability, not the platform: `os.geteuid` is Unix-only, so on + Windows the root check below raises AttributeError before the test can decide + anything. Shimming geteuid would not help — Windows ignores POSIX mode bits, + so `chmod 000` leaves the directory readable and the test fails on its real + assertion instead. Both reasons say the same thing: this test cannot run here + (#2643). + """ if os.geteuid() == 0: - import pytest pytest.skip("running as root: chmod 000 does not block scandir") (tmp_path / "a.py").write_text("def f(): pass\n") locked = tmp_path / "locked"