Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue37828

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Fix default mock_name in unittest.mock.assert_called error message
Type:behaviorStage:resolved
Components:Library (Lib)Versions:Python 3.9, Python 3.8
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: cjw296, mariocj89, michael.foord, miss-islington, pablogsal, xtreak
Priority:normalKeywords:newcomer friendly, patch

Created on2019-08-12 07:12 byxtreak, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 16166mergedcategulario,2019-09-15 20:37
PR 16229mergedmiss-islington,2019-09-17 11:16
Messages (4)
msg349444 -(view)Author: Karthikeyan Singaravelan (xtreak)*(Python committer)Date: 2019-08-12 07:12
In the format string for assert_called the evaluation order is incorrect and hence for mock's without name 'None' is printed whereas it should be 'mock' like for other messages. The error message is ("Expected '%s' to have been called." % self._mock_name or 'mock') . Here self._mock_name which is None is applied to form the string and then used with the string 'mock' in or combination. The fix would be to have the evaluation order correct like other error messages. Marking this as newcomer-friendly. Please leave this to new contributors as their 1st PR../python.exePython 3.9.0a0 (heads/master:f03b4c8a48, Aug 12 2019, 10:04:10)[Clang 7.0.2 (clang-700.1.81)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> from unittest.mock import Mock>>> m = Mock()>>> m.assert_called_once()Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/unittest/mock.py", line 854, in assert_called_once    raise AssertionError(msg)AssertionError: Expected 'mock' to have been called once. Called 0 times.>>> m.assert_called()Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/unittest/mock.py", line 844, in assert_called    raise AssertionError(msg)AssertionError: Expected 'None' to have been called.Thanks
msg352629 -(view)Author: Pablo Galindo Salgado (pablogsal)*(Python committer)Date: 2019-09-17 11:16
New changeset5f5f11faf9de0d8dcbe1a8a4eb35d2a4232d6eaa by Pablo Galindo (Abraham Toriz Cruz) in branch 'master':bpo-37828: Fix default mock_name in unittest.mock.assert_called error (GH-16166)https://github.com/python/cpython/commit/5f5f11faf9de0d8dcbe1a8a4eb35d2a4232d6eaa
msg352631 -(view)Author: miss-islington (miss-islington)Date: 2019-09-17 11:36
New changesetf668d2b775da4bcd07e142c4bc5ebd88165fadf4 by Miss Islington (bot) in branch '3.8':bpo-37828: Fix default mock_name in unittest.mock.assert_called error (GH-16166)https://github.com/python/cpython/commit/f668d2b775da4bcd07e142c4bc5ebd88165fadf4
msg352635 -(view)Author: Karthikeyan Singaravelan (xtreak)*(Python committer)Date: 2019-09-17 13:15
I don't think 3.7 needs a backport of the fix. I am closing this as fixed since all PRs are merged. Please reopen if a backport is needed. Thanks @categulario.
History
DateUserActionArgs
2022-04-11 14:59:19adminsetgithub: 82009
2019-09-17 13:16:12xtreaksetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-09-17 13:15:58xtreaksetmessages: +msg352635
2019-09-17 11:36:02miss-islingtonsetnosy: +miss-islington
messages: +msg352631
2019-09-17 11:16:46miss-islingtonsetpull_requests: +pull_request15827
2019-09-17 11:16:12pablogsalsetnosy: +pablogsal
messages: +msg352629
2019-09-15 20:37:39categulariosetkeywords: +patch
stage: patch review
pull_requests: +pull_request15775
2019-08-12 07:12:33xtreakcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp