Mocking away the url object in Pylons

前提是你 提交于 2019-12-10 18:26:40

问题


I want to test a method that calls the pylons.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?


回答1:


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?



来源:https://stackoverflow.com/questions/4275389/mocking-away-the-url-object-in-pylons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!