Is there a way to access the original function in a mocked method/function such that I can modify the arguments and pass it to the original functions?

You may want to use parameter wraps for the mock call. (Docs for reference.) This way the original function will be called, but it will have everything from Mock interface.

So for changing parameters called to original function you may want to try it like that:

org.py:

def func(x):
    print(x)

main.py:

from unittest import mock

import org


of = org.func
def wrapped(a):
    of('--{}--'.format(a))


with mock.patch('org.func', wraps=wrapped):
    org.func('x')
    org.func.assert_called_with('x')

result:

 --x--

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)