class A:
def foo(self):
# Make some network call or something
class B(A):
def bar(self):
self.foo()
...
class BTestCase(TestCase):
def setUp(self):
self.unit = B()
def test_bar(self):
with mock.patch.object(self.unit, 'foo') as mock_foo:
mock_foo.return_value = ...
result = self.unit.bar()
self.assertTrue(mock_foo.called)
...
要模拟在父模块中导入和使用的任何内容,您需要在父模块中模拟它。你知道吗
应付账款
双倍
在单元测试中
相关问题 更多 >
编程相关推荐