python學習筆記(控制語句)

來源:互聯網
上載者:User

標籤:

博主平時學python的時候、大多是複製網上別人現成的進行改動實現自己的測試的要求

所有python基礎文法其實掌握的很差

本來想最佳化下介面指令碼實現、發現基礎的迴圈控制語句都不知道怎麼寫

所以準備整理下

 1 #!/usr/bin/env python 2 # -*- coding: utf_8 -*- 3  4 import requests 5 import unittest 6 import re 7  8 class Testswcw_back(unittest.TestCase): 9     def setUp(self):10         print "介面測試開始"11 12     def tearDown(self):13         print "介面測試結束"14 15     def testlogin_1(self): #登入測試案例16         url = ‘http://localhost:8081/swcw/back/sysLogin.action‘17         postparams = {‘username‘:‘admin‘,‘password‘:‘123456‘}18         results = requests.post(url,postparams)19         pattern = re.compile(r‘toMain‘)20         match = pattern.search(results.url)21         if results.status_code == 200:22             if match != None:23                 print ‘用例測試結果:測試通過‘24             else:25                 print ‘用例測試結果:測試失敗‘26         else:27             print ‘用例測試結果:請求失敗‘28 29     def testlogin_2(self): #登入測試案例30         url = ‘http://localhost:8081/swcw/back/sysLogin.action‘31         postparams = {‘username‘:‘admin‘,‘password‘:‘123457‘} #密碼錯誤32         results = requests.post(url,postparams)33         pattern = re.compile(r‘toMain‘)34         match = pattern.search(results.url)35         if results.status_code == 200:36             if match != None:37                 print ‘用例測試結果:測試通過‘38             else:39                 print ‘用例測試結果:測試失敗‘40         else:41             print ‘用例測試結果:請求失敗‘42 43     def testlogin_3(self): #登入測試案例44         url = ‘http://localhost:8081/swcw/back/sysLogin.action‘45         postparams = {‘username‘:‘admin1‘,‘password‘:‘123456‘} #登入名稱錯誤46         results = requests.post(url,postparams)47         pattern = re.compile(r‘toMain‘)48         match = pattern.search(results.url)49         if results.status_code == 200:50             if match != None:51                 print ‘用例測試結果:測試通過‘52             else:53                 print ‘用例測試結果:測試失敗‘54         else:55             print ‘用例測試結果:請求失敗‘56 57 if __name__ == "__main__":58     unittest.main()

在原有指令碼的基礎上添加了控制語句

讓輸出的結果更清晰

if 語句 嵌套著另一個 if語句

if 條件:

   結果

else:

   結果

 

python學習筆記(控制語句)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.