mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-18 04:41:56 +00:00
fix: move pytest.importorskip below pytest import in skip-guarded tests
The original PR placed 'pwd = pytest.importorskip("pwd")' on line 4
but 'import pytest' on line 9 — NameError on module load. Same for
test_file_sync_back.py. Plus, the in-function 'pwd = pytest.importorskip'
calls in test_auto_detected_root_is_rejected confused Python's scope
analysis (later 'import pytest' made pytest local everywhere in the
function) and caused UnboundLocalError. Drop the now-redundant
in-function importorskip calls and rely on the module-level guard.
This commit is contained in:
parent
4e8b8573ca
commit
b959cfa056
2 changed files with 4 additions and 6 deletions
|
|
@ -1,13 +1,14 @@
|
||||||
"""Tests for gateway service management helpers."""
|
"""Tests for gateway service management helpers."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
pwd = pytest.importorskip("pwd")
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
pwd = pytest.importorskip("pwd")
|
||||||
|
|
||||||
import hermes_cli.gateway as gateway_cli
|
import hermes_cli.gateway as gateway_cli
|
||||||
from gateway import status
|
from gateway import status
|
||||||
from gateway.restart import (
|
from gateway.restart import (
|
||||||
|
|
@ -1284,20 +1285,17 @@ class TestSystemServiceIdentityRootHandling:
|
||||||
|
|
||||||
def test_auto_detected_root_is_rejected(self, monkeypatch):
|
def test_auto_detected_root_is_rejected(self, monkeypatch):
|
||||||
"""When root is auto-detected (not explicitly requested), raise."""
|
"""When root is auto-detected (not explicitly requested), raise."""
|
||||||
pwd = pytest.importorskip("pwd")
|
|
||||||
import grp
|
import grp
|
||||||
|
|
||||||
monkeypatch.delenv("SUDO_USER", raising=False)
|
monkeypatch.delenv("SUDO_USER", raising=False)
|
||||||
monkeypatch.setenv("USER", "root")
|
monkeypatch.setenv("USER", "root")
|
||||||
monkeypatch.setenv("LOGNAME", "root")
|
monkeypatch.setenv("LOGNAME", "root")
|
||||||
|
|
||||||
import pytest
|
|
||||||
with pytest.raises(ValueError, match="pass --run-as-user root to override"):
|
with pytest.raises(ValueError, match="pass --run-as-user root to override"):
|
||||||
gateway_cli._system_service_identity(run_as_user=None)
|
gateway_cli._system_service_identity(run_as_user=None)
|
||||||
|
|
||||||
def test_explicit_root_is_allowed(self, monkeypatch):
|
def test_explicit_root_is_allowed(self, monkeypatch):
|
||||||
"""When root is explicitly passed via --run-as-user root, allow it."""
|
"""When root is explicitly passed via --run-as-user root, allow it."""
|
||||||
pwd = pytest.importorskip("pwd")
|
|
||||||
import grp
|
import grp
|
||||||
|
|
||||||
root_info = pwd.getpwnam("root")
|
root_info = pwd.getpwnam("root")
|
||||||
|
|
@ -1309,7 +1307,6 @@ class TestSystemServiceIdentityRootHandling:
|
||||||
|
|
||||||
def test_non_root_user_passes_through(self, monkeypatch):
|
def test_non_root_user_passes_through(self, monkeypatch):
|
||||||
"""Normal non-root user works as before."""
|
"""Normal non-root user works as before."""
|
||||||
pwd = pytest.importorskip("pwd")
|
|
||||||
import grp
|
import grp
|
||||||
|
|
||||||
monkeypatch.delenv("SUDO_USER", raising=False)
|
monkeypatch.delenv("SUDO_USER", raising=False)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
"""Tests for FileSyncManager.sync_back() — pull remote changes to host."""
|
"""Tests for FileSyncManager.sync_back() — pull remote changes to host."""
|
||||||
|
|
||||||
fcntl = pytest.importorskip("fcntl")
|
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
@ -12,6 +11,8 @@ from unittest.mock import MagicMock, call, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
fcntl = pytest.importorskip("fcntl")
|
||||||
|
|
||||||
from tools.environments.file_sync import (
|
from tools.environments.file_sync import (
|
||||||
FileSyncManager,
|
FileSyncManager,
|
||||||
_sha256_file,
|
_sha256_file,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue