Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Display actual calls for unittest.assert_has_calls even if empty #113569

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@wookie184

Description

@wookie184

Feature or enhancement

Proposal:

Running this:

importunittestfromunittest.mockimportMock,callclassTestCase(unittest.TestCase):deftest_thing(self):mock=Mock()mock.assert_has_calls([call(a=1)])unittest.main()

currently gives this test failure message:

AssertionError: Calls not found.Expected: [call(a=1)]

This message does not imply that there were no calls. I propose that the test failure message is instead this:

AssertionError: Calls not found.Expected: [call(a=1)]  Actual: []

The "Actual" list is already displayed if there are calls. It's only excluded if there are no calls.


The logic that causes an empty list not to be displayed is in the_calls_repr method. For the other usages -assert_called_once_with,assert_called_once, andassert_not_called - the number of calls is displayed directly in the error message so it already says that there are no calls. This makes me think the current behaviour ofassert_has_calls is just an oversight rather than intentional behaviour.

I'd be happy to open a PR for this.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp