使用HTMLTestRunner生成报告时会执行两次用例,
@parameterized.expand(get_data())
def test_calculate(self, a, b, expect):
# 清屏
self.calculate.page_button_clear()
self.calculate.page_button_number(a)
self.calculate.page_button_add()
self.calculate.page_button_number(b)
self.calculate.page_button_equal()
# 它有返回值,强制转换为int,好比较
result = int(self.calculate.page_get_result())
try:
self.assertEqual(result, expect)
except AssertionError:
self.calculate.page_get_image()
raise
# 无限循环
class Report: @staticmethod def test_report(): # suite = unittest.TestSuite() suite = unittest.TestLoader().discover('./', pattern='test_ca*.py') # suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCase)) with open('../report-/{}html'.format(time.strftime('%Y_%m_%d %H_%M_%S')), 'wb') as f: HTMLTestRunner(stream=f, verbosity=2, title='测试报告', description='计算器').run(suite)
suite = unittest.TestLoader().discover(’./’, pattern=‘test_ca*.py’)是因为’test_ca*.py’中的test_calculate方法已经执行了一次,请问有什么好的方法让用例只执行一次呢