diff --git a/tests/hermes_cli/test_gateway_service.py b/tests/hermes_cli/test_gateway_service.py index d5917ac3fd3..2146b68d918 100644 --- a/tests/hermes_cli/test_gateway_service.py +++ b/tests/hermes_cli/test_gateway_service.py @@ -1,13 +1,14 @@ """Tests for gateway service management helpers.""" import os -pwd = pytest.importorskip("pwd") import subprocess from pathlib import Path from types import SimpleNamespace import pytest +pwd = pytest.importorskip("pwd") + import hermes_cli.gateway as gateway_cli from gateway import status from gateway.restart import ( @@ -1284,20 +1285,17 @@ class TestSystemServiceIdentityRootHandling: def test_auto_detected_root_is_rejected(self, monkeypatch): """When root is auto-detected (not explicitly requested), raise.""" - pwd = pytest.importorskip("pwd") import grp monkeypatch.delenv("SUDO_USER", raising=False) monkeypatch.setenv("USER", "root") monkeypatch.setenv("LOGNAME", "root") - import pytest with pytest.raises(ValueError, match="pass --run-as-user root to override"): gateway_cli._system_service_identity(run_as_user=None) def test_explicit_root_is_allowed(self, monkeypatch): """When root is explicitly passed via --run-as-user root, allow it.""" - pwd = pytest.importorskip("pwd") import grp root_info = pwd.getpwnam("root") @@ -1309,7 +1307,6 @@ class TestSystemServiceIdentityRootHandling: def test_non_root_user_passes_through(self, monkeypatch): """Normal non-root user works as before.""" - pwd = pytest.importorskip("pwd") import grp monkeypatch.delenv("SUDO_USER", raising=False) diff --git a/tests/tools/test_file_sync_back.py b/tests/tools/test_file_sync_back.py index 8a3c585c352..9c9da7dc502 100644 --- a/tests/tools/test_file_sync_back.py +++ b/tests/tools/test_file_sync_back.py @@ -1,6 +1,5 @@ """Tests for FileSyncManager.sync_back() — pull remote changes to host.""" -fcntl = pytest.importorskip("fcntl") import io import logging import os @@ -12,6 +11,8 @@ from unittest.mock import MagicMock, call, patch import pytest +fcntl = pytest.importorskip("fcntl") + from tools.environments.file_sync import ( FileSyncManager, _sha256_file,