模拟测试,补丁装饰器不起作用

时间:2019-12-02 12:28:07

标签: python mocking python-unittest nose

我的情况与using self in python @patch decorator非常相似。区别在于我使用了鼻子测试,因为从那以后我的测试类不是从x,y继承的,但是它的名称以unittest.TestCase

开头

在这个Test...类中,我想用Test...装饰方法,但是当我这样做时,根据调试器,根本不执行函数内部的代码。我的代码如下:

@patch

使用conext manager一切都可以正常工作,但这看起来比装饰器差。

class TestClass(object):
    ...

    @patch('path.to.submodule.requests.post')
    def test_something(self, mock_post):
        mock_post.return_value.status_code.return_value = 200  # this code is not executed
        ...

0 个答案:

没有答案
相关问题