Skip to content

fix(tests): restore run_ssh stub attribute for installer environment tests - #786

Open
mrbobbytables wants to merge 1 commit into
projectbluefin:mainfrom
mrbobbytables:fix-installer-run-ssh-patch
Open

fix(tests): restore run_ssh stub attribute for installer environment tests#786
mrbobbytables wants to merge 1 commit into
projectbluefin:mainfrom
mrbobbytables:fix-installer-run-ssh-patch

Conversation

@mrbobbytables

Copy link
Copy Markdown
Contributor

What

Fixes #762Unit Tests failing on main with:

AttributeError: <module 'tests.shared.ssh_steps'> has no attribute 'run_ssh'

raised from tests/unit/test_installer_environment.py when it does
monkeypatch.setattr(ssh_steps, "run_ssh", fake_run_ssh).

Root cause

Three unit-test import helpers replace sys.modules["tests.shared.ssh_steps"]
with a bare stub module and never restore the original afterwards:

  • tests/unit/test_dx_steps.py
  • tests/unit/test_software_steps.py
  • tests/unit/test_flatpak_permissions_steps.py

None of these stubs set a run_ssh attribute. Since the CI job runs
pytest -n auto (pytest-xdist), whichever worker executes one of these three
tests first permanently corrupts that worker's sys.modules entry for
tests.shared.ssh_steps for the remainder of the session — there's no
teardown restoring the real module.

tests/unit/test_installer_environment.py later does
import tests.shared.ssh_steps as ssh_steps and expects to be able to patch
ssh_steps.run_ssh. When it runs in a worker whose ssh_steps module was
already replaced by one of the bare stubs above, monkeypatch.setattr raises
AttributeError because the stub has no run_ssh attribute at all.

This reproduces locally with coverage run -m pytest -n auto tests/unit/
(consistent 4 failures), but passes when the installer environment test file
is run in isolation — a classic cross-test pollution bug that only shows up
under parallel/xdist ordering.

Fix

Give each of the three offending stubs a run_ssh MagicMock, matching the
pattern already used by every other suite's stub in this file
(hardware, flatcar, nvidia, lifecycle, offline_boot,
update_failure, common_steps), so the stubbed module always exposes the
attribute that other tests expect to find or patch.

Testing

  • python3 -m pytest -n auto tests/unit/ -q — 1527 passed (run 3x to rule out
    xdist ordering flakiness); previously reproduced 4 failures in
    test_installer_environment.py under the same command before this fix.
  • ruff check on the three changed files shows the same pre-existing findings
    (import sorting / SIM117 / stale noqa) as on main before this change —
    none introduced by this patch.

Note: I based this branch on main since v4 does not exist in
projectbluefin/testsuite (verified via git ls-remote --heads upstream);
main is the repository's only long-lived/default branch.

— hive: backend=copilot model=claude-sonnet-5

🐝 Hive Agent: contributor | SHA: e67f900b

…tests

Three unit-test import helpers (test_dx_steps.py, test_software_steps.py,
test_flatpak_permissions_steps.py) replace sys.modules['tests.shared.ssh_steps']
with a bare stub module that has no run_ssh attribute, and never restore the
original module afterwards. Under pytest-xdist, once one of these tests runs
in a worker, that worker's sys.modules entry for tests.shared.ssh_steps stays
permanently stubbed for the rest of the session.

tests/unit/test_installer_environment.py later does
'import tests.shared.ssh_steps as ssh_steps' and
'monkeypatch.setattr(ssh_steps, "run_ssh", fake_run_ssh)' expecting the real
module. When the corrupted stub lands in the same worker first, setattr raises
AttributeError because the stub has no run_ssh attribute at all, failing Unit
Tests on main.

Give each offending stub a run_ssh MagicMock, matching the pattern already
used by the other suites' stubs (hardware, flatcar, nvidia, lifecycle,
offline_boot, update_failure, common_steps), so the stubbed module always
exposes the attribute other tests expect to find or patch.

Fixes projectbluefin#762

Signed-off-by: mrbobbytables <mrbobbytables@users.noreply.github.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kubestellar-hive kubestellar-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by @castrojo for Hive auto-merge on green CI.

@kubestellar-hive kubestellar-hive Bot added the lgtm This PR has been approved by a maintainer label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ci-maintainer] Unit Tests fail on main: installer environment tests patch missing run_ssh

2 participants