[TIP] Mock and function namespace
Mathieu Drapeau
matdrapeau at gmail.com
Thu Mar 15 11:30:11 PDT 2012
Hi all,
I am fairly new to mock and I would like to know how to fix an issue during
module imports and scope of functions.
Here is a snippet that explain problem I am dealing with:
from mock import MagicMock
import sys
sys.func = lambda: 'x'
from sys import func
print func()
# outputs 'x'
sys.func = MagicMock(return_value='mocked_x')
print func()
# outputs 'x', it is not mocked
How could I fix this?
Thanks,
Mat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120315/39fd45d7/attachment.htm>
More information about the testing-in-python
mailing list