[TIP] Mocking import functions
David Stanek
dstanek at dstanek.com
Fri Feb 7 08:07:10 PST 2014
Instead of mock.patch('miners.tasks_utils.mechanize_url') you should try
mock.patch('twitter_profile.mechanize_url').
Once your twitter_profile module is imported it will have a reference to
mechanize_url. When you patch miners.tasks_utils you are not changing this
reference.
On Fri, Feb 7, 2014 at 10:42 AM, Mahdi Yusuf <yusuf.mahdi at gmail.com> wrote:
> I am at my wits end pretty much. I am not sure what is happening here.
>
> I am unable to mock an import function. My code is here<https://gist.github.com/myusuf3/685083e70bf3f93fd43c>.
> After some reading I know you patch where the function is used not where
> its defined.
>
> I have also tried everything else but the mechanize_url is till running as
> implemented in code not mocked in test.
>
> Thoughts?
>
> --
> Mahdi Yusuf
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
>
--
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
www: http://dstanek.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140207/34ca28ce/attachment.htm>
More information about the testing-in-python
mailing list