Spying on a pure function call in my unit test

Viewed 129

I am trying to mock the call to a function and still have the effect of the function apply. I found the solution using Python wraps, but all examples I found are applied to mocking the member method of a class. In my case, I have a pure function (not defined in a class). This seems to not work with the usual examples, as they require you to instantiate the class first I guess to obtain the real version of the method to pass into wraps.

Can this be done with pure functions? https://wesmckinney.com/blog/spying-with-python-mocks/

My code:

<this_module.py>

def my_function:
  does something important

def test_my_function:
  with patch.object("this_module", "my_function", wraps="this_module.my_function")
0 Answers
Related