当使用unittest框架作为测试套件运行时,测试用例没有运行

时间:2018-03-28 15:29:16

标签: python-unittest

这是我的测试,导入的测试类中有一些案例

from apa_login import Apa_login
from processmap import Show_processmap
import unittest,HTMLTestRunner,apa_login,processmap


def suite(self):
    suite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Apa_login)
    suite = unittest.TestLoader().loadTestsFromTestCase(Show_processmap)
    return suite


if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    runner.run(suite)
    print suite
那么它给了我这个结果? $ python testrun.py

以0.001s进行0测试

它不应该是0测试,对吧?

1 个答案:

答案 0 :(得分:0)

您需要通过调用TestSuite函数将runner.run()实例传递给suite()。您当前正在传递suite函数。

runner.run(suite())  # Pass the TestSuite by invoking suite()

另请注意,如果该函数不属于某个类,则应该从self中删除suite()参数。

相关问题