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
b37f43f9
Commit
b37f43f9
authored
Jul 15, 2015
by
Robert Collins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
Patch from Nicola Palumbo and Laurent De Buyst.
parent
acb3a4d8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
3 deletions
+17
-3
Lib/unittest/mock.py
Lib/unittest/mock.py
+9
-3
Lib/unittest/test/testmock/testmock.py
Lib/unittest/test/testmock/testmock.py
+3
-0
Misc/ACKS
Misc/ACKS
+2
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/unittest/mock.py
View file @
b37f43f9
...
@@ -519,8 +519,14 @@ class NonCallableMock(Base):
...
@@ -519,8 +519,14 @@ class NonCallableMock(Base):
side_effect
=
property
(
__get_side_effect
,
__set_side_effect
)
side_effect
=
property
(
__get_side_effect
,
__set_side_effect
)
def
reset_mock
(
self
):
def
reset_mock
(
self
,
visited
=
None
):
"Restore the mock object to its initial state."
"Restore the mock object to its initial state."
if
visited
is
None
:
visited
=
[]
if
id
(
self
)
in
visited
:
return
visited
.
append
(
id
(
self
))
self
.
called
=
False
self
.
called
=
False
self
.
call_args
=
None
self
.
call_args
=
None
self
.
call_count
=
0
self
.
call_count
=
0
...
@@ -531,11 +537,11 @@ class NonCallableMock(Base):
...
@@ -531,11 +537,11 @@ class NonCallableMock(Base):
for
child
in
self
.
_mock_children
.
values
():
for
child
in
self
.
_mock_children
.
values
():
if
isinstance
(
child
,
_SpecState
):
if
isinstance
(
child
,
_SpecState
):
continue
continue
child
.
reset_mock
()
child
.
reset_mock
(
visited
)
ret
=
self
.
_mock_return_value
ret
=
self
.
_mock_return_value
if
_is_instance_mock
(
ret
)
and
ret
is
not
self
:
if
_is_instance_mock
(
ret
)
and
ret
is
not
self
:
ret
.
reset_mock
()
ret
.
reset_mock
(
visited
)
def
configure_mock
(
self
,
**
kwargs
):
def
configure_mock
(
self
,
**
kwargs
):
...
...
Lib/unittest/test/testmock/testmock.py
View file @
b37f43f9
...
@@ -237,6 +237,9 @@ class MockTest(unittest.TestCase):
...
@@ -237,6 +237,9 @@ class MockTest(unittest.TestCase):
# used to cause recursion
# used to cause recursion
mock
.
reset_mock
()
mock
.
reset_mock
()
def
test_reset_mock_on_mock_open_issue_18622
(
self
):
a
=
mock
.
mock_open
()
a
.
reset_mock
()
def
test_call
(
self
):
def
test_call
(
self
):
mock
=
Mock
()
mock
=
Mock
()
...
...
Misc/ACKS
View file @
b37f43f9
...
@@ -1533,3 +1533,5 @@ Tarek Ziadé
...
@@ -1533,3 +1533,5 @@ Tarek Ziadé
Gennadiy Zlobin
Gennadiy Zlobin
Doug Zongker
Doug Zongker
Peter Åstrand
Peter Åstrand
Laurent De Buyst
Nicola Palumbo
Misc/NEWS
View file @
b37f43f9
...
@@ -66,6 +66,9 @@ Core and Builtins
...
@@ -66,6 +66,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
18622
:
unittest
.
mock
.
mock_open
().
reset_mock
would
recurse
infinitely
.
Patch
from
Nicola
Palumbo
and
Laurent
De
Buyst
.
-
Issue
#
24608
:
chunk
.
Chunk
.
read
()
now
always
returns
bytes
,
not
str
.
-
Issue
#
24608
:
chunk
.
Chunk
.
read
()
now
always
returns
bytes
,
not
str
.
-
Issue
#
18684
:
Fixed
reading
out
of
the
buffer
in
the
re
module
.
-
Issue
#
18684
:
Fixed
reading
out
of
the
buffer
in
the
re
module
.
...
...
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