Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9c3f284d
Commit
9c3f284d
authored
Feb 26, 2019
by
Xtreak
Committed by
Chris Withers
Feb 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Autospec functions should propagate mock calls to parent GH-11273
parent
f1b9abe3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
0 deletions
+23
-0
Lib/unittest/mock.py
Lib/unittest/mock.py
+8
-0
Lib/unittest/test/testmock/testmock.py
Lib/unittest/test/testmock/testmock.py
+13
-0
Misc/NEWS.d/next/Library/2018-12-21-09-54-30.bpo-21478.5gsXtc.rst
...S.d/next/Library/2018-12-21-09-54-30.bpo-21478.5gsXtc.rst
+2
-0
No files found.
Lib/unittest/mock.py
View file @
9c3f284d
...
...
@@ -321,6 +321,14 @@ class _CallList(list):
def
_check_and_set_parent
(
parent
,
value
,
name
,
new_name
):
# function passed to create_autospec will have mock
# attribute attached to which parent must be set
if
isinstance
(
value
,
FunctionTypes
):
try
:
value
=
value
.
mock
except
AttributeError
:
pass
if
not
_is_instance_mock
(
value
):
return
False
if
((
value
.
_mock_name
or
value
.
_mock_new_name
)
or
...
...
Lib/unittest/test/testmock/testmock.py
View file @
9c3f284d
...
...
@@ -1830,5 +1830,18 @@ class MockTest(unittest.TestCase):
self.assertEqual(type(call.parent().parent), _Call)
def test_parent_propagation_with_create_autospec(self):
def foo(a, b):
pass
mock = Mock()
mock.child = create_autospec(foo)
mock.child(1, 2)
self.assertRaises(TypeError, mock.child, 1)
self.assertEqual(mock.mock_calls, [call.child(1, 2)])
if __name__ == '__main__':
unittest.main()
Misc/NEWS.d/next/Library/2018-12-21-09-54-30.bpo-21478.5gsXtc.rst
0 → 100644
View file @
9c3f284d
Calls to a child function created with :func:`unittest.mock.create_autospec`
should propagate to the parent. Patch by Karthikeyan Singaravelan.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment