Drop url object in Pylons

I want to test a method that calls the pylons.url object. However, calling this in tests results in an error:

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

So, I would like to replace the pylons.url object with the layout from the mock library.

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

However, this is not like a url object.

Is there a way to mock this object?

+3
source share
1 answer

For the patch to work, you must give it the full path to the variable in the module that you are actually fixing. Therefore, instead of "pylons.url" you will correct "my_project.my_module.url" and inside my_module.py you will do

from pylons import url

It makes sense?

+2
source

Source: https://habr.com/ru/post/1776849/


All Articles