Clarify spy_return_list order#565
Open
WilliamDEdwards wants to merge 1 commit intopytest-dev:mainfrom
Open
Conversation
nicoddemus
requested changes
Mar 13, 2026
| * ``spy_return``: contains the last returned value of the spied function. | ||
| * ``spy_return_iter``: contains a duplicate of the last returned value of the spied function if the value was an iterator and spy was created using ``.spy(..., duplicate_iterators=True)``. Uses `tee <https://docs.python.org/3/library/itertools.html#itertools.tee>`__) to duplicate the iterator. | ||
| * ``spy_return_list``: contains a list of all returned values of the spied function (new in ``3.13``). | ||
| * ``spy_return_list``: contains a list of all returned values of the spied function (new in ``3.13``). If the mock was called multiple times, the list is sorted descendingly: the last value comes first. |
Member
There was a problem hiding this comment.
This is not right, the last call comes last:
class C:
def foo(self, x): return x
def test(mocker):
spy = mocker.spy(C, "foo")
c = C()
c.foo(10)
c.foo(20)
print(spy.spy_return_list)
assert 0----------------------------- Captured stdout call -----------------------------
[10, 20]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.