it is possible to monkeypatch a local variable introduced in a function body?
<p>In <a href="http://doc.pytest.org/en/latest/monkeypatch.html" rel="noreferrer">py.test monkeypatching/mocking documentation</a> this is not mentioned, but it is possible to monkeypatch a local variable introduced in a function body?</p>

<p>my experiment:</p>

<pre><code>def my_method():
    my_var = 'foo'
    return my_var[:2]
</code></pre>

<p>test is:</p>

<pre><code>def test_my_method(monkeypatch):
    monkeypatch.setattr(my_module.MyClass.my_method.my_var, lambda: 'bar')
    assert my_method() == 'ba'
</code></pre>

<blockquote>
  <p>AttributeError: 'function' object at MyClass.my_method has no
  attribute 'my_var'</p>
</blockquote>