fix(tests): make Windows pytest collection portable - #84073
Conversation
Related: #81926 fixes the same doctor-test collection seam. This PR also adds the separate platform-temp-directory repair for the parallel-runner test. |
monerostar
left a comment
There was a problem hiding this comment.
Native Win11 verification (monerostar)
Host: Windows 11 (10.0.26200), Python 3.11.15, pytest 9.1.1
SHA: 23b13dd78
Baseline (upstream/main @ 222465d84)
python -m pytest tests/hermes_cli/test_doctor_journal_modes.py --collect-only -q -o addopts=
# ERROR collecting ... AttributeError: module 'os' has no attribute 'geteuid'
test_run_tests_parallel.py still has:
_HANDOFF_DIR = Path(os.environ.get("TMPDIR", "/tmp")) / "hermes-isolation-probe"On this host collect still succeeds for that file because C:\tmp already exists, so the /tmp fallback does not raise. That masks the issue #83935 class on machines that happen to have \tmp. A missing-parent TMPDIR still fails mkdir with WinError 3 (checked separately).
This PR
# TMPDIR cleared in PowerShell
python -m pytest tests/hermes_cli/test_doctor_journal_modes.py tests/test_run_tests_parallel.py --collect-only -q -o addopts=
# 37 tests collected
python -m pytest tests/hermes_cli/test_doctor_journal_modes.py -q -rs -o addopts=
# 25 passed, 2 skipped (chmod no-op on Windows)
Both collection holes this PR targets are fixed here. Sibling map for maintainers: #81926 is doctor-journal-only (also green on this box earlier); #74083 is handoff-only and much further behind main. This tip is the complete two-file path.
LGTM from a Windows contributor host.
|
Native Win11 verification (monerostar overnight, not a maintainer merge signal) Host: Windows 11 Pro Collection on current main still dies here. at the class-body This PR: same file collects 27 tests and The isolation-probe handoff change ( Sibling overlap: #74083 also retargets that isolation-probe handoff at the platform temp dir. The geteuid + nested Small, correct, I would take it. |
fix(tests): make Windows pytest collection portable — small, correct, no blocking issues. Observations:
|
…rows read_header_bytes_preopen answers None for a live connection, a missing file and an unreadable file alike, so the error string doctor prints is now chosen rather than inherited from the OSError. These cases pin that choice: the missing file keeps its errno text, and the chmod-000 file is still reported as a permission problem rather than collapsing into the generic message — the behaviour the raw open() gave before. test_reason_does_not_open_the_file is the load-bearing one. It patches builtins.open to raise and asserts _unreadable_reason still answers, which fixes the constraint that makes the helper safe to call on a database path at all: stat() and access() read metadata and take no file descriptor, so no close() of ours can cancel the file's advisory locks. A future edit that reached for open() here to get a better message would reintroduce the original bug on the error path, and this test fails loudly if it does. The root check is written as hasattr(os, "geteuid") and os.geteuid() == 0 rather than the bare call the surrounding tests use. skipif conditions are evaluated at collection time and os.geteuid is POSIX-only, so the bare form raises AttributeError and takes the whole module down on Windows. The pre-existing occurrences are left alone — #81926 and #84073 are already open against exactly those lines, and this only avoids adding a third instance of the same defect.
Summary
os.geteuid()while pytest is importing the doctor journal-mode tests on Windowstempfile.gettempdir()for the parallel-runner handoff directory instead of assuming/tmpFixes #83935.
Testing
.venv\Scripts\python.exe -m pytest --collect-only -q tests\hermes_cli\test_doctor_journal_modes.py tests\test_run_tests_parallel.py.venv\Scripts\python.exe -m pytest -q tests\hermes_cli\test_doctor_journal_modes.pyNote: running
tests\test_run_tests_parallel.pyfully on this Windows checkout still times out inside its subprocess runner smoke test after collection succeeds; this PR targets the collection-time abort described in the issue.