Skip to content

msg: in failure mock causes TypeError: got multiple values for keyword argument msg #3

@jorge-romero

Description

@jorge-romero

Summary

When a scenario mock includes msg: in a success: false response, the framework crashes with TypeError: fail_json() got multiple values for keyword argument 'msg'. This is caused by fail_json receiving msg both as an explicit keyword argument and again via **response_data.

Affected file

ansible_playtest/ansible_mocker/mock_ansible_adapter.py

error_msg = response_data.get("error_message", "Mock service failure")
module.fail_json(msg=error_msg, **response_data)
# ↑ if response_data still contains 'msg:', Python raises TypeError

Reproducer

Scenario YAML:

service_mocks:
  my_module:
    success: false
    msg: "Connection refused"   # ← triggers the crash

Running any test with this scenario raises:

TypeError: fail_json() got multiple values for keyword argument 'msg'

Expected behaviour

The framework should either:

  • Document that msg: is a reserved key and raise a clear validation error at scenario-load time, or
  • Consume msg from response_data before calling fail_json (e.g. prefer it as error_msg if present).

Suggested fix

# Pop 'msg' from response_data to avoid the collision
error_msg = response_data.pop("msg", None) or response_data.pop("error_message", "Mock service failure")
module.fail_json(msg=error_msg, **response_data)

Workaround

Use error_message: instead of msg: in all success: false mock responses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions