Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除python单元测试中的修补依赖项_Python_Python 3.x_Python Unittest_Python Unittest.mock - Fatal编程技术网

如何删除python单元测试中的修补依赖项

如何删除python单元测试中的修补依赖项,python,python-3.x,python-unittest,python-unittest.mock,Python,Python 3.x,Python Unittest,Python Unittest.mock,给定以下单元测试 @patch("requests.get") def test_create_resource_success(self, request_get): request_get_mock.return_value = Mock(ok=True) request_get_mock.return_value.json.return_value = {'key': 'value'} success = create_resource(data

给定以下单元测试

@patch("requests.get")
def test_create_resource_success(self, request_get):
    request_get_mock.return_value = Mock(ok=True)
    request_get_mock.return_value.json.return_value = {'key': 'value'}
    success = create_resource(data)
    self.assertTrue(success)


我如何确保requests.get的所有其他单元测试用法没有被修补?如何在拆卸过程中重置修补?

您不需要重置,这就是修补程序的真正含义does@wim我注意到它正在影响我的其他单元测试,如果我全部运行,一些单元测试将失败,因为requests.get仍然被模拟。如果我单独运行那些受影响的失败测试,它们就会成功。问题出在测试套件的其他地方,而不是这个补丁修饰符。