在这些情况下,我会使用多重继承。例如:
第一。我定义了一个包含将要合并的方法的类。
import osclass CustomAssertions: def assertFileExists(self, path): if not os.path.lexists(path): raise AssertionError('File not exists in path "' + path + '".')现在,我定义一个从unittest.TestCase和CustomAssertion继承的类
import unittestclass MyTest(unittest.TestCase, CustomAssertions): def test_file_exists(self): self.assertFileExists('any/file/path')if __name__ == '__main__': unittest.main()


