开发者

Mocking away the url object in Pylons

I want to test a method that calls the p开发者_StackOverflowylons.url object. However calling this in the tests leads to an error:

TypeError: No object (name: url) has been registered for this thread

So I'd like to replace the pylons.url object with a Mock from the mock library.

@patch('pylons.url')
def my_test(self, url_mock):
    ...

However, this doesn't seem to replace the url object.

Is there a way to mock out this object?


In order for patch to work you need to give it the full path to the variable in the MODULE that you are actually patching. So rather than 'pylons.url' you would be patching 'my_project.my_module.url' and inside my_module.py you would be doing

from pylons import url

Does that make sense?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜