title: 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?
body: <p>I'd like to modify the arguments passed to a method in a module, as opposed to replacing its return value.</p>
  
  <p>I've found a way around this, but it seems like something useful and has turned into a lesson in mocking.</p>
  
  <h3>module.py</h3>
  
  <pre><code>from third_party import ThirdPartyClass
  
  ThirdPartyClass.do_something('foo', 'bar')
  ThirdPartyClass.do_something('foo', 'baz')
  </code></pre>
  
  <h3>tests.py</h3>
  
  <pre><code>@mock.patch('module.ThirdPartyClass.do_something')
  def test(do_something):
      # Instead of directly overriding its return value
      # I'd like to modify the arguments passed to this function.
  
      # change return value, no matter inputs
      do_something.return_value = 'foo'
  
      # change return value, based on inputs, but have no access to the original function
      do_something.side_effect = lambda x, y: y, x
  
      # how can I wrap do_something, so that I can modify its inputs and pass it back to the original function?
      # much like a decorator?
  </code></pre>
  
  <p>I've tried something like the following, but not only is it repetitive and ugly, it doesn't work. After some PDB introspection.. I'm wondering if it's simply due to however this third party library works, as I do see the original functions being called successfully when I drop a pdb inside the <code>side_effect</code>. </p>
  
  <p>Either that, or some auto mocking magic I'm just not following that I'd love to learn about.</p>
  
  <pre><code>def test():
      from third_party import ThirdPartyClass
      original_do_something = ThirdPartyClass.do_something
  
      with mock.patch('module.ThirdPartyClass.do_something' as mocked_do_something:
          def side_effect(arg1, arg2):
              return original_do_something(arg1, 'overridden')
  
          mocked_do_something.side_effect = side_effect
  
          # execute module.py
  </code></pre>
  
  <p>Any guidance is appreciated!</p>