Skip to content

Commit ab56c39

Browse files
cliffhallclaude
andcommitted
test(fetch): look for node and npm only in the fake bin directory
A real Node.js or npm in /usr/bin (a distribution install) was still found by the runner, so the missing-tool tests could find it and run real npm. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent baf1306 commit ab56c39

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/fetch/tests/test_readability_subprocess.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import os
19+
import shutil
1920
import stat
2021
import subprocess
2122
import sys
@@ -58,14 +59,22 @@ def html(body: str) -> httpx.Response:
5859

5960
@pytest.fixture
6061
def bindir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
61-
"""An empty directory that is the first entry on PATH, ahead of system tools.
62+
"""An empty directory that is the only place the runner looks for node and npm.
6263
63-
The real Node.js and npm (in /usr/local/bin and the like) are left off, so
64-
only the fakes a test writes here are found.
64+
The fake scripts' own utilities (sleep, cat, mkdir) still come from the
65+
system directories on PATH, but the runner's lookup sees this directory
66+
alone, so a real Node.js or npm installed anywhere (/usr/bin included, as
67+
a distribution installs it) is never found or run.
6568
"""
6669
path = tmp_path / "bin"
6770
path.mkdir()
6871
monkeypatch.setenv("PATH", os.pathsep.join([str(path), "/usr/bin", "/bin"]))
72+
which = shutil.which # the real one, before the module's is replaced
73+
74+
def only_bindir(name: str) -> str | None:
75+
return which(name, path=str(path))
76+
77+
monkeypatch.setattr(readability_js.shutil, "which", only_bindir)
6978
return path
7079

7180

0 commit comments

Comments
 (0)