Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

python - How to get currently running testcase name from testsuite in unittest

How can I get currently running testcase name, while in the testsuite collection there are 16 testcases. Tests are executed sequentially (in the order of adding test to the testSuite collection). When I add all tests to testSuite collection I can preview this object but how can I get currently executing test while tests are running. Maybe some variable holds this information?

example:

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())

Tests are executed using Selenium-RC framework.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Hopefully one of those is useful for your needs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...