Skip to content

bug(tests): TestEnsureUserSystemdEnv fails on Python 3.12 — FakePath subclass ignores redirected path in __new__ #2243

@teyrebaz33

Description

@teyrebaz33

Bug

tests/hermes_cli/test_gateway_service.py::TestEnsureUserSystemdEnv::test_sets_xdg_runtime_dir_when_missing fails on Python 3.12 / WSL2.

Root Cause

The test uses a FakePath subclass to redirect /run/user/42 to a temp directory:

class FakePath(type(RealPath())):
    def __new__(cls, *args):
        if p == "/run/user/42":
            return RealPath.__new__(cls, str(tmp_path))

In Python 3.12, PosixPath.__new__ ignores the path argument passed to RealPath.__new__ and re-initializes the internal path from the original string. So FakePath("/run/user/42").exists() returns False instead of True, and XDG_RUNTIME_DIR is never set.

Fix

Replace FakePath subclass with a direct monkeypatch on Path.exists:

monkeypatch.setattr(gateway_cli.Path, "exists", lambda self: str(self) == "/run/user/42")

This patches the method directly on the class used by the module under test, avoiding the Python 3.12 __new__ behavior entirely.

Evidence

FAILED tests/hermes_cli/test_gateway_service.py::TestEnsureUserSystemdEnv::test_sets_xdg_runtime_dir_when_missing
AssertionError: assert None == '/run/user/42'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions