How to write a custom `.assertFoo()` method in Python?

前端 未结 3 1753
天涯浪人
天涯浪人 2020-12-07 22:52

I\'m writing some test cases for my application using Python\'s unittest. Now I need to compare a list of objects with a list of another objects to check if the objects from

3条回答
  •  渐次进展
    2020-12-07 23:49

    Just an example to sum up with a numpy comparaison unittest

    import numpy as np
    class CustomTestCase(unittest.TestCase):
        def npAssertAlmostEqual(self, first, second, rtol=1e-06, atol=1e-08):
            np.testing.assert_allclose(first, second, rtol=rtol, atol=atol)
    
    
    class TestVector(CustomTestCase):
        def testFunction(self):
            vx = np.random.rand(size)
            vy = np.random.rand(size)
            self.npAssertAlmostEqual(vx, vy)
    

提交回复
热议问题