Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Releases
Unreleased
----------

* Preserve assertion failures when ``assert_has_calls`` receives ``calls`` as a keyword.

* `#547 <https://github.com/pytest-dev/pytest-mock/issues/547>`_: Added ``SpyType`` for annotating ``mocker.spy`` results.
* Dropped support for EOL Python 3.9.
* `#147 <https://github.com/pytest-dev/pytest-mock/issues/147>`_: Removed handling of ``RuntimeError: stop called on unstarted patcher``, which can no longer occur in the supported Python versions.
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_mock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def assert_has_calls_wrapper(
msg = str(e)
if __mock_self.call_args_list is not None:
actual_calls = list(__mock_self.call_args_list)
expect_calls = args[1]
expect_calls = args[1] if len(args) > 1 else kwargs["calls"]
introspection = ""
from itertools import zip_longest

Expand Down
7 changes: 7 additions & 0 deletions tests/test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,3 +1428,10 @@ def handle_get():

assert Class1.get() == 1
assert Class2.get() == 2


def test_assert_has_calls_keyword(mocker: MockerFixture) -> None:
stub = mocker.stub()
stub("actual")
with pytest.raises(AssertionError):
stub.assert_has_calls(calls=[mocker.call("expected")])