研究Python中的继承,到目前为止,我的理解是,如果一个子类打算让基类的方法执行与基类不同的操作,那么它只会覆盖基类的方法。你知道吗
以HowDoI为例,我们在测试中看到了这一点_你好从unittest.TestCase
继承的HowdoiTestCase
类覆盖TestCase
的setUp()
函数(它只是pass
):
def setUp(self):
self.queries = ['format date bash',
'print stack trace python',
'convert mp4 to animated gif',
'create tar archive']
self.pt_queries = ['abrir arquivo em python',
'enviar email em django',
'hello world em c']
self.bad_queries = ['moe',
'mel']
到目前为止还可以。你知道吗
试验_你好然后继续覆盖tearDown()
,但是它只被写入pass
(根据基类的定义)。tearDown()在任何地方都不会使用。你知道吗
您描述的结构可能会简化为以下代码:
试着回答你的问题:
setUp
和tearDown
方法在unittest运行程序中使用(顾名思义-测试前后)。你知道吗其中一些原因可能是:
setUp
和tearDown
是可选的,默认情况下有空的实现TLDR:由于意外或个人喜好。你知道吗
相关问题 更多 >
编程相关推荐