我有下面的代码测试MyClass.mymethod公司名称:
from unittest import main
from mocker import Mocker, MockerTestCase
Class test_A(MockerTestCase):
def setUp(self):
self.m=Mock()
MyClass.mymethod = self.m.mock()
self.m.result(None)
self.m.count(0,None)
self.m.replay()
def test_me(self):
#Do something about MyClass.method
def tearDown(self):
self.m.restore()
self.m.verify()
我还有另一个代码测试,不模仿MyClass.mymethod公司名称:
^{pr2}$但是,当我做“noestests test_A.py test_B.py”时,它看起来像是在测试完test_A.py并进入test_B.py之后,MyClass.mymethod仍然是模拟的。不知道为什么以及如何避开它。谢谢!在
行:
确实将
MyClass.mymethod()
替换为新对象。对MyClass.mymethod
的所有后续引用都将指向模拟对象,即使这些引用位于不同的类中。在您需要的是一种替换
^{pr2}$MyClass.mymethod()
的方法,它只在test_A
类中工作。实现这一点的最简单方法是在您的tearDown
方法中还原原始的mymethod
:相关问题 更多 >
编程相关推荐