我的代码如下图所示:
import unittest,os
case_path=os.path.join(os.getcwd(),"test_login")
suite=unittest.defaultTestLoader.discover(case_path,pattern="test_*.py")
print(suite)
if __name__=='__main__':
runner=unittest.TextTestRunner()
runner.run(suite)
#unittest.main(defaultTest='suite',verbosity=2)
运行结果如下:
Launching unittests with arguments python -m unittest E:/Testcmmcar-2.0/src/script/login/testrunner.py in E:\Testcmmcar-2.0\src\script\login
Ran 0 tests in 0.000s
OK
<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<test_login_failure.test_login_failure testMethod=test_no_authority>, <test_login_failure.test_login_failure testMethod=test_password_error>, <test_login_failure.test_login_failure testMethod=test_password_null>, <test_login_failure.test_login_failure testMethod=test_username_error>, <test_login_failure.test_login_failure testMethod=test_username_null>]>]>, <unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<test_login_success.test_login_success testMethod=test_login>]>]>, <unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<test_logout.test_logout testMethod=test_logout>]>]>]>
Process finished with exit code 0
Empty test suite.
输出 suite,不是已经证明我的测试套件中是有用例的吗!为什么运行结果显示为空呢?