Python Learning Notes (Control statements)

Source: Internet
Author: User

Bloggers usually learn python when, mostly copy online others ready to make changes to achieve their own test requirements

All Python basic syntax is actually poorly mastered.

Would like to optimize the implementation of the interface script, the discovery of the basic loop control statements do not know how to write

So get ready to clean up.

1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 ImportRequests5 ImportUnitTest6 ImportRe7 8 classTestswcw_back (unittest. TestCase):9     defsetUp (self):Ten         Print "interface Test started" One  A     defTearDown (self): -         Print "end of interface test" -  the     defTestlogin_1 (self):#Login Test Cases -URL ='http://localhost:8081/swcw/back/sysLogin.action' -Postparams = {'username':'Admin','Password':'123456'} -Results =requests.post (url,postparams) +Pattern = Re.compile (r'Tomain') -Match =Pattern.search (Results.url) +         ifResults.status_code = = 200: A             ifMatch! =None: at                 Print 'use case test result: Test pass' -             Else: -                 Print 'use case test Result: Test Failed' -         Else: -             Print 'use case test Result: request failed' -  in     defTestlogin_2 (self):#Login Test Cases -URL ='http://localhost:8081/swcw/back/sysLogin.action' toPostparams = {'username':'Admin','Password':'123457'}#Password Error +Results =requests.post (url,postparams) -Pattern = Re.compile (r'Tomain') theMatch =Pattern.search (Results.url) *         ifResults.status_code = = 200: $             ifMatch! =None:Panax Notoginseng                 Print 'use case test result: Test pass' -             Else: the                 Print 'use case test Result: Test Failed' +         Else: A             Print 'use case test Result: request failed' the  +     defTestlogin_3 (self):#Login Test Cases -URL ='http://localhost:8081/swcw/back/sysLogin.action' $Postparams = {'username':'admin1','Password':'123456'}#Logon name Error $Results =requests.post (url,postparams) -Pattern = Re.compile (r'Tomain') -Match =Pattern.search (Results.url) the         ifResults.status_code = = 200: -             ifMatch! =None:Wuyi                 Print 'use case test result: Test pass' the             Else: -                 Print 'use case test Result: Test Failed' Wu         Else: -             Print 'use case test Result: request failed' About  $ if __name__=="__main__": -Unittest.main ()

Added a control statement based on the original script

Make the output clearer

If statement nested with another if statement

If condition:

Results

Else

Results

Python Learning Notes (Control statements)

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.