How can I use Python's `patch.object` to change the return value of a method called within another method in my unit tests?

If you need to mock multiple functions at the same time, you can stack patch.object decorators.

Example:

# test_case_3.py
import foo
from mock import patch

@patch.object(foo, 'some_fn')
@patch.object(foo, 'other_fn')
def test_foo(test_other_fn, test_some_fn):
    test_some_fn.return_value = 'test-val-1'
    test_other_fn.return_value = 'test-val-2'
    tmp = foo.Foo()
    assert tmp.method_1() == 'test-val-1'
    assert tmp.method_1() == 'test-val-2'

In this example, we mock both some_fn and other_fn using multiple decorators. Note that the order of decorators matters — the decorator closer to the function definition is passed later in the parameter list.