fix(tests): restore run_ssh stub attribute for installer environment tests - #786
Open
mrbobbytables wants to merge 1 commit into
Open
fix(tests): restore run_ssh stub attribute for installer environment tests#786mrbobbytables wants to merge 1 commit into
mrbobbytables wants to merge 1 commit into
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Approved by @castrojo for Hive auto-merge on green CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #762 —
Unit Testsfailing onmainwith:raised from
tests/unit/test_installer_environment.pywhen it doesmonkeypatch.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.pytests/unit/test_software_steps.pytests/unit/test_flatpak_permissions_steps.pyNone of these stubs set a
run_sshattribute. Since the CI job runspytest -n auto(pytest-xdist), whichever worker executes one of these threetests first permanently corrupts that worker's
sys.modulesentry fortests.shared.ssh_stepsfor the remainder of the session — there's noteardown restoring the real module.
tests/unit/test_installer_environment.pylater doesimport tests.shared.ssh_steps as ssh_stepsand expects to be able to patchssh_steps.run_ssh. When it runs in a worker whosessh_stepsmodule wasalready replaced by one of the bare stubs above,
monkeypatch.setattrraisesAttributeErrorbecause the stub has norun_sshattribute 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_sshMagicMock, matching thepattern 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 theattribute that other tests expect to find or patch.
Testing
python3 -m pytest -n auto tests/unit/ -q— 1527 passed (run 3x to rule outxdist ordering flakiness); previously reproduced 4 failures in
test_installer_environment.pyunder the same command before this fix.ruff checkon the three changed files shows the same pre-existing findings(import sorting / SIM117 / stale noqa) as on
mainbefore this change —none introduced by this patch.
Note: I based this branch on
mainsincev4does not exist inprojectbluefin/testsuite(verified viagit ls-remote --heads upstream);mainis the repository's only long-lived/default branch.— hive: backend=copilot model=claude-sonnet-5
🐝 Hive Agent:
contributor| SHA:e67f900b