refactor: simplify shutil usage in workstation backend tests
Lint / pssa (push) Successful in 9s
Lint / python (push) Successful in 22s

This commit is contained in:
2026-05-26 19:00:38 +02:00
parent 189b865a52
commit 0a1c455e54
+5 -10
View File
@@ -6,12 +6,14 @@ NOT ``getGuestIPAddress`` (which would block 30-60s without VMware Tools).
from __future__ import annotations from __future__ import annotations
import shutil
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
import pytest import pytest
from ci_orchestrator.backends import workstation as ws_mod
from ci_orchestrator.backends.errors import BackendNotAvailable, BackendOperationFailed from ci_orchestrator.backends.errors import BackendNotAvailable, BackendOperationFailed
from ci_orchestrator.backends.protocol import VmHandle from ci_orchestrator.backends.protocol import VmHandle
from ci_orchestrator.backends.workstation import WorkstationVmrunBackend from ci_orchestrator.backends.workstation import WorkstationVmrunBackend
@@ -165,8 +167,7 @@ def test_is_running_returns_false_when_absent(
# ── _resolve_vmrun(explicit=None) paths ─────────────────────────────────────── # ── _resolve_vmrun(explicit=None) paths ───────────────────────────────────────
def test_resolve_vmrun_uses_which(monkeypatch: pytest.MonkeyPatch, fake_vmrun: str) -> None: def test_resolve_vmrun_uses_which(monkeypatch: pytest.MonkeyPatch, fake_vmrun: str) -> None:
import shutil as _shutil monkeypatch.setattr(shutil, "which", lambda _name: fake_vmrun)
monkeypatch.setattr(_shutil, "which", lambda _name: fake_vmrun)
backend = WorkstationVmrunBackend() # no explicit path backend = WorkstationVmrunBackend() # no explicit path
assert backend.vmrun_path == fake_vmrun assert backend.vmrun_path == fake_vmrun
@@ -174,22 +175,16 @@ def test_resolve_vmrun_uses_which(monkeypatch: pytest.MonkeyPatch, fake_vmrun: s
def test_resolve_vmrun_uses_default_win_path( def test_resolve_vmrun_uses_default_win_path(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None: ) -> None:
import shutil as _shutil
from ci_orchestrator.backends import workstation as ws_mod
fake_default = tmp_path / "vmrun.exe" fake_default = tmp_path / "vmrun.exe"
fake_default.write_bytes(b"") fake_default.write_bytes(b"")
monkeypatch.setattr(_shutil, "which", lambda _name: None) monkeypatch.setattr(shutil, "which", lambda _name: None)
monkeypatch.setattr(ws_mod, "_DEFAULT_WIN_VMRUN", str(fake_default)) monkeypatch.setattr(ws_mod, "_DEFAULT_WIN_VMRUN", str(fake_default))
backend = WorkstationVmrunBackend() backend = WorkstationVmrunBackend()
assert backend.vmrun_path == str(fake_default) assert backend.vmrun_path == str(fake_default)
def test_resolve_vmrun_raises_when_nothing_found(monkeypatch: pytest.MonkeyPatch) -> None: def test_resolve_vmrun_raises_when_nothing_found(monkeypatch: pytest.MonkeyPatch) -> None:
import shutil as _shutil monkeypatch.setattr(shutil, "which", lambda _name: None)
from ci_orchestrator.backends import workstation as ws_mod
monkeypatch.setattr(_shutil, "which", lambda _name: None)
monkeypatch.setattr(ws_mod, "_DEFAULT_WIN_VMRUN", "/nonexistent/vmrun.exe") monkeypatch.setattr(ws_mod, "_DEFAULT_WIN_VMRUN", "/nonexistent/vmrun.exe")
with pytest.raises(BackendNotAvailable): with pytest.raises(BackendNotAvailable):
WorkstationVmrunBackend() WorkstationVmrunBackend()