[TIP] Unable to mock.patch methods in __init__.py

Ratnadeep Debnath rtnpro at transifex.com
Sat Jul 14 12:48:53 PDT 2012


Hi,

I am trying to patch gettext(), ugettext(), etc. methods in
django/utils/translation/__init__.py (django.utils.translation). I am
trying something like below:

from mock import patch

def mock_gettext(s):
   # do something

@patch('django.utils.translation.gettext', mock_gettext)
def myview(request):
   ...
   ...

This is just not working. I see no reason why it should not. I
successfully patched `_trans` object from the same module above.

Can anyone help me out?

Thanks,
Regards,
rtnpro



More information about the testing-in-python mailing list