This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lisroach
Recipients berker.peksag, docs@python, lisroach, michael.foord, vstinner
Date 2017-01-13.18:17:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484331474.46.0.558237777572.issue28911@psf.upfronthosting.co.za>
In-reply-to
Content
It took me a little while to wrap my brain around this, but you are definitely right that the documentation is not sufficient, your changes are an improvement. 

My wonder is, should we change the documentation or be looking at the code itself? I have always interpreted the method as asserting that only one call was made with the matching signature. If I want to test for call count I can just assert mock.call_count == 1.

The code could instead look like this: 

def assert_called_once_with(_mock_self, *args, **kwargs):
    self = _mock_self
    if not self.mock_calls.count(call(*args, **kwargs)) == 1:
        msg = ("Expected '%s' to be called once with %r %r. Called %s times."          % (self._mock_name or 'mock', args, kwargs, self.mock_calls.count(call(*args,  **kwargs))))
        raise AssertionError(msg)


Then again, if users have been using this to assert that the call_count is one (which is likely since it is in the examples documentation), this change would break backwards functionality.

Thoughts?
History
Date User Action Args
2017-01-13 18:17:54lisroachsetrecipients: + lisroach, vstinner, michael.foord, docs@python, berker.peksag
2017-01-13 18:17:54lisroachsetmessageid: <1484331474.46.0.558237777572.issue28911@psf.upfronthosting.co.za>
2017-01-13 18:17:54lisroachlinkissue28911 messages
2017-01-13 18:17:54lisroachcreate