我会将文档字符串传递给工厂函数,并用于
type手动构造类。
def make_testcase(filename, myfunc, docstring): def test_something(self): data = loadmat(filename) result = myfunc(data) self.assertTrue(result > 0) clsdict = {'test_something': test_something, '__doc__': docstring} return type('ATest', (unittest.TestCase,), clsdict)MyTest = makeTestCase('some_filename', my_func, 'This is a docstring')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)