【发布时间】:2016-04-18 19:37:03
【问题描述】:
我试图只运行一个类中提供的单元测试中的一个测试。所以假设
class MytestSuite(unittest.TestCase):
def test_false(self):
a = False
self.assertFalse(a, "Its false")
def test_true(self):
a = True
self.assertTrue(a, "Its true")
我只想运行 test_false。根据本网站和在线提供的问答,我在主类中使用了以下代码行
if __name__ == "__main__": # Indentation was wrong
singletest = unittest.TestSuite()
singletest.addTest(MytestSuite().test_false)
unittest.TextTestRunner().run(singletest)
我在尝试添加测试时不断出错。主要是:
文件“C:\Python27\Lib\unittest\case.py”,第 189 行,在 init
(self.class, methodName))
ValueError:main.MytestSuite'> 中没有这样的测试方法:runTest
我的班级需要特定的 runTest 方法吗?有没有办法运行可能属于不同套件的特定测试?例如,方法 A 属于 suite class 1 和 method B 属于 suite class 2。令人惊讶的是,事实证明这在网上很难找到。有多个通过命令行执行此操作的示例,但不是通过程序本身。
【问题讨论】: