Python+selenium+unitest use case failed re-run

Source: Internet
Author: User

After a lot of study and debugging UnitTest code, later found a can also re-run Setup () and Deardown () solution, that is to modify the source, we re-build a module suite class to cover the original Testsuite class

Instance code:

[Python]View PlainCopy
  1. Class Suit (UnitTest. TestSuite):
  2. def run (self, result, debug=False):
  3. Failcount = 1#失败总运行次数
  4. Class_num = 1
  5. TopLevel = False
  6. if GetAttr (result, ' _testrunentered ', false) is False:
  7. result._testrunentered = TopLevel = True
  8. For test in self :
  9. Case_num = 1
  10. if Result.shouldstop:
  11. Break
  12. Success_flag = True
  13. While Success_flag:
  14. if _isnotsuite (test):
  15. self._teardownpreviousclass (test, result)
  16. self._handlemodulefixture (test, result)
  17. self._handleclasssetup (test, result)
  18. Result._previoustestclass = test.__class__
  19. if (GetAttr (test.__class__, ' _classsetupfailed ', False) or
  20. GetAttr (result, ' _modulesetupfailed ', False)):
  21. if Class_num > Failcount:
  22. Success_flag = False
  23. Else:
  24. Time.sleep (5)
  25. Result._previoustestclass = None
  26. Print ' class%s '%s re-initialized execution '% (test.__class__,class_num)
  27. Class_num + = 1
  28. Continue
  29. If not debug:
  30. Test (Result)
  31. Else:
  32. Test.debug ()
  33. if result.result[-1][0]==1 or result.result[-1][0]==2:#结果为fail和err用例判断
  34. if Case_num > Failcount:
  35. Success_flag = False
  36. Else:
  37. print ' use case%s '%s re-executed '% (test,case_num)
  38. Case_num + = 1
  39. Else:
  40. Success_flag = False
  41. if TopLevel:
  42. Self._teardownpreviousclass (None, result)
  43. Self._handlemoduleteardown (Result)
  44. result._testrunentered = False
  45. return result



Then test using

Alltests=suit. Suit ()

Alltests.addtest(Widgettestcase ("Testdefaultsize"))

Runner =htmltestrunner.htmltestrunner (stream=fp,verbosity=2,title= ' Android test Report ', description= ' use case execution: ',)
Runner.run (alltests)

After running, the use cases with failed re-run will be printed in the test report for easy reference.

Python+selenium+unitest use case failed re-run

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.