I usually use:
def create_patch(self, name, value = None):
patcher = patch(name)
mock = patcher.start()
mock.return_value = value
self.addCleanup(patcher.stop)
return mock
def assertXmlEqual(self, a, b):
with open(a, 'r') as f:
axml = f.read()
with open(b, 'r') as f:
bxml = f.read()
self.assertEqual(loads(dumps((parse(axml)))), loads(dumps((parse(bxml)))))
and in testcases:
mockobj = self.create_patch('mymodule.myclass.mymethod', 'myvalue')
self.assertXmlEqual('expect.xml', 'result.xml')
But for every unit test class, I have to copy it.
Is there any way to make these more testcase-independent, more like a lib, like Moq
and Assert
in .net and mock
and expect
in Ruby?
Aucun commentaire:
Enregistrer un commentaire