第二个可能成为“单元测试奇怪代码”的系列。我有以下功能我正在测试: def filter_queryset(self):
"""
Filter our base queryset
"""
# Get our base queryset
queryset = self.get_queryset()
if self.tags:
我的代码使用unittest框架运行测试。这是一个什么样的我的方法之一,看起来像基本思想: def _RunTestsList(self, lTestsPaths):
""" Runs all tests in lTestsPaths with the unittest module
"""
for sTestPath in lTestsPaths:
class A(object):
def get_value(self):
return "foo"
class B(A):
def get_value(self):
value = super(B, self).get_value()
value + "bar"
return value
鉴于上述类,当我想写一个测
从this question继,我试图修补A()类Mock()这样,当B()被初始化,素被用作基本如: class A(object): ...
class B(A): ...
def setUp(self):
with patch('A', new_callable=Mock) as MockObject:
self.b = B()
self.b.__cl