Skip to content
Discussion options

You must be logged in to vote

There is a useful distinction from an ordinary circular reference here. An unrestricted Mock invents tolist, and its default return value is another mock. Repeating that conversion creates new objects, so JSON's circular-reference check does not catch the chain.

For the test that triggered this, configure the mocked call to return the actual response-shaped data rather than letting its default mock reach the renderer.

from unittest.mock import Mock

client = Mock()
client.fetch.return_value = {"items": [{"id": 1}]}

# Pass client.fetch() through the same response code as the real result.

If you want to test rejection of an unsupported object, Mock(spec_set=object) raises TypeError with th…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@browniebroke
Comment options

Answer selected by browniebroke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants