gpt4 book ai didi

python - 如何从单元测试中的测试套件获取当前正在运行的测试用例名称

转载 作者:IT老高 更新时间:2023-10-28 20:56:59 25 4
gpt4 key购买 nike

如何获得当前运行的测试用例名称,而在测试套件集合中有 16 个测试用例。测试按顺序执行(按照将测试添加到 testSuite 集合的顺序)。当我将所有测试添加到 testSuite 集合时,我可以预览这个对象,但是如何在测试运行时获取当前正在执行的测试。也许某个变量保存了这些信息?

示例:

def suite():
testSuite= unittest.TestSuite()
testSuite.addTest(FlightsTestCases('test_sel__reservation_one_way_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_tair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_easyjet_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_ryanair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_ryanair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_duplicated'))
testSuite.addTest(FlightsTestCases('test_reservation_wrong_card_lowcost'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_wrong_credit_card'))

return testSuite

if __name__ == "__main__":
result = unittest.TextTestRunner(verbosity=2).run(suite())
sys.exit(not result.wasSuccessful())

使用 Selenium-RC 框架执行测试。

最佳答案

unittest.TestCase.shortDescription()

Returns a description of the test, or None if no description has been provided. The default implementation of this method returns the first line of the test method’s docstring, if available, or None.

unittest.TestCase.id()

Return a string identifying the specific test case. This is usually the full name of the test method, including the module and class name.

希望其中之一对您的需求有用。

关于python - 如何从单元测试中的测试套件获取当前正在运行的测试用例名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7797442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com