Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Test exists in multiple py files in unittest group mode

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Def all_case (self): case_dir = os.path.dirname (os.getcwd ()) + os.sep + "test" # set the file path of the test script testcase = unittest.TestSuite () # testcase = Suit () discover = unittest.defaultTestLoader.discover (case_dir, pattern='*.py', top_level_dir=None) # store all use cases in testcase to modify the script Control the running order testcase.addTest (InitializeWebdriver ("initializedriver")) # instantiate it by placing it in the first test, and the initializedriver method in the InitializeWebdriver class initializes driver for test_suite in discover: for test_case in test_suite: # add use case to testcase testcase.addTest (test_case) # testcase.addTest (CloseDriver ("closedr")) # add exit operation Closedr in the CloseDriver class turns off driver return testcase # using an example class Login (InitializeWebdriver): # all test inherits and initializes the class InitializeWebdriver of driver By using the driver class variable in the InitializeWebdriver class to ensure the unique transmission of driver def test_get_url_login (self): Log.info ("login url") InitializeWebdriver.driver.get (url) # Note: # test_suite usage self-interpretation: all test classes and methods inherited from the unittest.TestCase class form a list with classes (methods). The loop execution of the list# setUpClass and tearDownClass is only valid for all test methods under the same class. So when the py file of the test class is finished, the execution of the next py file will still trigger setUpClass.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report