Skip to content

tests: narrow the secrets-file existence mock - #2576

Draft
ideaship wants to merge 1 commit into
stack/1-interface-fact-key-dotsfrom
stack/2-narrow-secrets-path-mock
Draft

tests: narrow the secrets-file existence mock#2576
ideaship wants to merge 1 commit into
stack/1-interface-fact-key-dotsfrom
stack/2-narrow-secrets-path-mock

Conversation

@ideaship

@ideaship ideaship commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants