test: skip the unreadable-dir detect test on non-POSIX platforms - #2651
test: skip the unreadable-dir detect test on non-POSIX platforms#2651rajarshidattapy wants to merge 1 commit into
Conversation
`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 Graphify-Labs#2643
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Graphify review — findings
This PR modifies a single test, test_detect_surfaces_unreadable_dir_instead_of_silent_skip, in tests/test_detect.py. It adds a pytest.mark.skipif guard that skips the test on platforms lacking os.geteuid, moves the os and pytest imports to module level (removing the inline imports), and expands the docstring to explain the platform-specific rationale for the skip.
No blocking issues surfaced.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 346 functions depend on the 346 functions this change touches.
Health — grade A; no new coupling hotspots.
Verification — 346 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 346 function(s) in the blast radius were not formally verified this run
Fixes #2643.
The bug
test_detect_surfaces_unreadable_dir_instead_of_silent_skipguards itself against running asroot — a
chmod 000directory is still readable by root, so the test would assert nothing.That guard calls
os.geteuid(), which is Unix-only, so on Windows the guard raises before thetest can decide anything:
Fix
The capability guard from the issue:
Why not shim
geteuidThe issue notes a shim would not help, and that holds up — I checked rather than assumed.
chmod 000is not enforced on Windows, so the directory stays readable and the test fails onits real assertion instead:
So both of the test's POSIX assumptions fail here, and skipping is the honest outcome rather
than a workaround. That reasoning is recorded in the docstring so nobody re-litigates it by
adding a shim later.
Guarding on
hasattr(os, "geteuid")rather thansys.platformalso keeps the check pointed atwhat the test actually needs — the coverage is unaffected on POSIX, where the attribute exists
and the test runs exactly as before.
Also
Dropped the function-local
import osandimport pytest; both are already module-levelimports in this file, and the local
import pytestwould have shadowed the decorator's needfor it at module scope.
Verification
SKIPPED [1] tests/test_detect.py:2521: POSIX-only: needs geteuid() and chmod 000 to actually block scandir.removed and no new failures.
As the issue says, a repo-wide grep confirms this was the only
geteuidoccurrence, so the fixis self-contained.