fix(test): import mirror submodules before patching in integration tests
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled

Ensure pkgmgr.actions.mirror.* submodules are imported before unittest.mock.patch
to avoid AttributeError when patching dotted paths (e.g. check_cmd).
Stabilizes mirror CLI integration tests in CI.

https://chatgpt.com/share/693ed9f5-9918-800f-a880-d1238b3da1c9
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-14 16:38:24 +01:00
parent dcbe16c5f0
commit 724c262a4a

View File

@@ -15,6 +15,7 @@ are patched to keep tests deterministic and CI-safe.
from __future__ import annotations
import importlib
import io
import os
import runpy
@@ -56,8 +57,18 @@ class TestIntegrationMirrorCommands(unittest.TestCase):
}
)
# Helper: patch with create=True so missing modules/symbols don't explode
# Helper: patch with create=True so missing symbols don't explode.
# IMPORTANT: patch() does not auto-import submodules when resolving dotted names.
# Example failure: AttributeError: pkgmgr.actions.mirror has no attribute 'check_cmd'
# → so we import the parent module first (if it exists).
def _p(target: str, **kwargs):
module_name = target.rsplit(".", 1)[0]
try:
importlib.import_module(module_name)
except ModuleNotFoundError:
# If the module truly doesn't exist, create=True may still allow patching
# in some cases, but dotted resolution can still fail. Best-effort.
pass
return patch(target, create=True, **kwargs)
# Fake result for remote provisioning (preview-safe)
@@ -114,7 +125,6 @@ class TestIntegrationMirrorCommands(unittest.TestCase):
% (cmd_repr, exc.code, buffer.getvalue())
)
return buffer.getvalue()
finally: