简体   繁体   English

如何使用 unittests mock.patch 模拟两个函数

[英]how to mock two functions using unittests mock.patch

I need to mock two functions inside my API post method.我需要在我的 API post 方法中模拟两个函数。 Mocking just one function worked well, but I have no idea how to do it when i need to mock two functions?只模拟一个函数效果很好,但是当我需要模拟两个函数时,我不知道该怎么做?

@unittest.mock.patch('path.to.first.function.thefirstfunction')
def test_connector_post(mock_thefirstfunction):
... 

Any ideas?有任何想法吗?

stack the decorators!堆叠装饰器!

@unittest.mock.patch("functionA")
@unittest.mock.patch("functionB")
def test_foo(...):
    ... 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM