Skip to content

Make it easier to assert call arguments of multiple calls #15

Description

@ollipa

Right now if a user wants to assert call arguments for multiple calls in specific order, the only option is to use has_calls method:

>>> from chainmock.mock import call
>>> mocker(Teapot).mock("add_tea").has_calls([call("oolong"), call("black")])
<chainmock._api.Assert object at ...>
>>> Teapot().add_tea("oolong")
>>> Teapot().add_tea("black")

I see these problems with this approach:

  • Use caller needs to know all the calls beforehand and new calls can't be easily added afterwards.
  • There is no way to use this with match_args_* methods.
  • Using call type is a bit cumbersome.

Proposal

  • Add new methods:
    • awaited_with
    • called_with
    • match_args_await
    • match_args_call
  • Assert call args in the order the methods are called.

The above code could be rewritten as follows:

>>> mocker(Teapot).mock("add_tea").called_with("oolong").called_with("black")
<chainmock._api.Assert object at ...>
>>> Teapot().add_tea("oolong")
>>> Teapot().add_tea("black")

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions