A unit tests passes in a list of objects into a method. The method uses jsonpickle.encode on the objects.
Well and good, but what to do when unit test sends list of mocked objects and runs into infinite recursion?
Here is an example of the code:
import jsonpickle
from mock.mock import MagicMock
class Foo(object):
def __init__(self):
pass
def encodeFoos(list_of_foos):
[jsonpickle.encode(x) for x in list_of_foos]
def works():
list_of_foos = [Foo()]
encodeFoos(list_of_foos=list_of_foos)
def unit_test_doesnt_work():
list_of_mock_foos = [MagicMock()]
encodeFoos(list_of_mock_foos)
unit_test_doesnt_work()
The error that is thrown is: RuntimeError: maximum recursion depth exceeded since jsonpickle apparently travels down an infinite tree in the mocked object.
how can I keep the production code as is (encodeFoos) and not run into maximum recursion when passing in mock objects?
Thanks!