Building Python Automation use case framework--problems

Source: Internet
Author: User

Problems encountered in building the Python automation framework process based on 76572411:

One, the lack of test kits: The test set code is as follows, will run all the E:\Software\sichuantest\test\case directory and test_*.py matching use cases

ImportUnitTest fromUtils. HtmltestrunnerImportHtmltestrunnerImport Time#Note When using a suite, use the (class name ("Method name") for multiple use cases in a single py file.#Import multiple py classes under, with (Py name. Class name)Allcase='E:\\software\\sichuantest\\test\\case'     #indicates the path to the folder where the py file to be automatically founddefcreatesuite (): Testunit=UnitTest. TestSuite () Discover= Unittest.defaultTestLoader.discover (Allcase,#folder path to findPattern ='test_*.py',#The name of the module to be tested, the. py file that begins with startTop_level_dir = None)#the top-level directory of the test module, that is, the test case is not placed in a multilevel directory, set to none    #use for loop out of suite, then loop out case     forSuiteinchDiscover: forCaseinchsuite:testunit.addTests (case)Print(Testunit)returnTestunitif __name__=='__main__': Now= Time.strftime ("%y-%m-%d-%h_%m_%s", Time.localtime (Time.time ())) # Get current time   report='e:\\software\\sichuantest\\report\\'+now+"test_suit.html" # stitching according to the current time. XML report file name  with open (report,'WB') as F:runner= Htmltestrunner (f, verbosity=2, title='HTML Report Test', description='HTML Report Content') Runner.run (Createsuite ())

Second, the report.xml generated by different use cases will be overwritten, and the code for generating. XML will be modified as follows

if __name__=='__main__': file_name= Os.path.split (__file__) [ -1].split ('.') [0] # Get the use case file name   Report= Report_path +'\\'+ file_name +'_report.html' # stitching the. XML report file name according to the file name  with open (report,'WB') as F:runner= Htmltestrunner (f, verbosity=2, title='HTML Report Test', description='HTML Report Content') Runner.run (Testbaidu ('Test_search'))

Third, a single use case log name Unified Test.log, will cause all use cases of logs are hit in Test.log inside

1, by the use case file names are also stitched into the log in a way to differentiate

Modify the value of pattern in the log.py file as follows

Pattern = C.get ('pattern'if and C.get ('pattern')  Else'% (asctime) s-% (filename) s[line:% (Lineno) d]-% (levelname) s-% (message) s '

Modify the value of log in the Config.yml file, modify the following

log:    file_name:test.log    5    console_level:warning    file_level:debug    '  % (asctime) s-% (filename) s[line:% (Lineno) d]-% (levelname) s-% (message) s'

2, through the use case name splicing log name way to distinguish

Not yet, haha haha haha

Building Python Automation use case framework--problems

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.