''' 生成测试报告 https://www.lambdatest.com/blog/generating-xml-and-html-report-in-pyunit-for-test-automation/ unittest https://codedec.com/tutorials/how-to-generate-html-report-for-pytest-execution/ https://docs.pytest.org/en/7.1.x/_modules/_pytest/reports.html https://www.geeksforgeeks.org/python-logging-test-output-to-a-file/ ''' import unittest import unittest.mock import unittest.loader import unittest.case import sys import webbrowser def setUpModule(): """ :return: """ print("all module case before") def tearDownModule(): """ :return: """ print("all module case after") class Test(unittest.TestCase): """ """ def testcase(self): """ :return: """ print("this is Test class case") def main(self, out=sys.stderr, verbosity=2): """ :param out: :param verbosity: :return: """ loader = unittest.TestLoader() suite = loader.loadTestsFromModule(sys.modules[__name__]) unittest.TextTestRunner(out, verbosity=verbosity).run(suite) class Test2(unittest.TestCase): """ """ def testcase(self): """ :return: """ print("this is Test2 class case") def main(self, out=sys.stderr, verbosity=2): """ :param out: :param verbosity: :return: """ loader = unittest.TestLoader() suite = loader.loadTestsFromModule(sys.modules[__name__]) unittest.TextTestRunner(out, verbosity=verbosity).run(suite) if __name__ == '__main__': """ """ # 写入报告 with open('testmodule.txt', 'w') as f: a=Test2() a.main(f) b=Test() b.main(f) webbrowser.open('testmodule.txt',new=0,autoraise=True) #打开文档 unittest.main()
标签:__,python,unittest,import,main,verbosity,out From: https://www.cnblogs.com/geovindu/p/18472828