tests: narrow the secrets-file existence mock - #2576
Draft
ideaship wants to merge 1 commit into
Draft
Conversation
The setup_password fixture patched the existence check with a flat
return_value:
mocker.patch("osism.utils.rabbitmq.os.path.exists", return_value=exists)
That target reads as module-scoped but resolves to the attribute on the
shared os.path module, so for the duration of the patch os.path.exists
answers the same way for every caller in the process.
load_rabbitmq_password() then calls
osism.tasks.conductor.utils.load_yaml_file, whose import pulls in ansible.
Ansible's config manager reads ansible/config/base.yml and checks
os.path.exists first, gets the mocked answer, and raises:
AnsibleError: Missing base YAML definition file (bad install?):
.../site-packages/ansible/config/base.yml
so test_password_file_missing_returns_none fails -- with a message that
points at ansible's installation rather than at the mock -- whenever
ansible-core happens to be importable. It passes today only because the
unit-test environment has no ansible-core, which makes the suite quietly
dependent on that staying true.
Answer for the path under test and defer everything else to the real
function. The test keeps asserting what it asserted; it just stops
answering questions it was not asked.
Verified in two virtualenvs differing only in whether ansible-core is
installed: before, the test failed in the one that had it; after, the
module passes in both.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Roger Luethi <luethi@osism.tech>
This was referenced Aug 6, 2026
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.
The
setup_passwordfixture patched the existence check with a flatreturn_value:That target reads as module-scoped but resolves to the attribute on the shared
os.pathmodule, so for the duration of the patchos.path.existsanswers the same way for every caller in the process.load_rabbitmq_password()then callsosism.tasks.conductor.utils.load_yaml_file, whose import pulls in ansible. Ansible's config manager readsansible/config/base.ymland checksos.path.existsfirst, gets the mocked answer, and raises:So
test_password_file_missing_returns_nonefails — with a message pointing at ansible's installation rather than at the mock — whenever ansible-core happens to be importable. It passes today only because the unit-test environment has no ansible-core, which leaves the suite quietly dependent on that staying true.This answers for the path under test and defers everything else to the real function. The test keeps asserting what it asserted; it just stops answering questions it was not asked.
Verification. Two virtualenvs differing only in whether ansible-core is installed: before, the test fails in the one that has it; after, the module passes in both.
Not required by any other change here, but it removes a tripwire under the next PR in the stack, which installs ansible for the integration job.
🤖 Generated with Claude Code