import HTMLTestRunnerimport unittestimport os# 1. 完成使用discover()方法构造套件的方法 if __name__ == ‘__main__‘: current_path = os.path.dirname(__file__) testcase_path = os.path.join(current_path, ‘testcase‘) discover = unittest.defaultTestLoader.discover(testcase_path,pattern="test*.py",top_level_dir=None) suits = unittest.TestSuite() suits.addTest(discover) unittest.main(defaultTest=‘suits‘)# 2. 掌握:HTMLTestRunner 生产报告的方法 if __name__ == ‘__main__‘: current_path = os.path.dirname(__file__) testcase_path = os.path.join(current_path, ‘testcase‘) discover = unittest.defaultTestLoader.discover(testcase_path,pattern="test*.py",top_level_dir=None) suits = unittest.TestSuite() suits.addTest(discover) report_path = ‘report‘+time.strftime(‘%Y_%m_%d_%H_%M_%S‘)+‘.html‘ fp = open(report_path,‘wb‘) runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title=‘自动化测试报告‘,description=‘执行测试用例测试报告‘) runner.run(suits)