Skip to content

The agent that grows with you

test(plugins): fail the pathlib probes the loader guards, not os.stat

ethernetc1807fc57036
diff --git a/tests/plugins/test_plugin_loader_unreadable.py b/tests/plugins/test_plugin_loader_unreadable.py
index e813987db62..e7376b67b83 100644
--- a/tests/plugins/test_plugin_loader_unreadable.py
+++ b/tests/plugins/test_plugin_loader_unreadable.py
@@ -8,15 +8,22 @@ from plugins import plugin_loader
def _deny(monkeypatch, denied: Path) -> None:
- """chmod 000 does not bite as root, so fail the stat of the denied child's ``__init__.py``."""
- real_stat = Path.stat
-
- def stat(self, *args, **kwargs):
- if self.parent == denied:
- raise PermissionError(13, "Permission denied", str(self))
- return real_stat(self, *args, **kwargs)
-
- monkeypatch.setattr(Path, "stat", stat)
+ """chmod 000 does not bite as root, so fail the probes of the denied child's ``__init__.py``.
+
+ ``Path.exists``/``is_dir`` route through ``os.path`` on 3.12+, which swallows
+ ``PermissionError`` into False; the loader's own guard sees the error only when the
+ pathlib probe raises, so fail both layers the way a real ACL denial can."""
+ real_exists, real_is_dir = Path.exists, Path.is_dir
+
+ def refuse(method):
+ def probe(self, *args, **kwargs):
+ if self.parent == denied or self == denied:
+ raise PermissionError(13, "Permission denied", str(self))
+ return method(self, *args, **kwargs)
+ return probe
+
+ monkeypatch.setattr(Path, "exists", refuse(real_exists))
+ monkeypatch.setattr(Path, "is_dir", refuse(real_is_dir))
def test_iter_plugin_dirs_skips_unreadable_child(tmp_path, monkeypatch, caplog):