Skip to content

Clarify spy_return_list order#565

Open
WilliamDEdwards wants to merge 1 commit intopytest-dev:mainfrom
WilliamDEdwards:clarify-spy_return_list-order
Open

Clarify spy_return_list order#565
WilliamDEdwards wants to merge 1 commit intopytest-dev:mainfrom
WilliamDEdwards:clarify-spy_return_list-order

Conversation

@WilliamDEdwards
Copy link

No description provided.

* ``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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants