Best Python code snippet using avocado_python
run.py
Source:run.py
1# --*-- coding : utf-8 --*--2# Project : python223# Current file : run.py4# Author : Administrator5# Create time : 2019-09-19 15:196# IDE : PyCharm7# TODO æé¿å¾è¦, è¿æ¥å¾ç, å æ²¹ï¼8# åå§åä¸ä¸ªå¯¹è±¡ suite æµè¯å¥ä»¶ï¼éåï¼9import unittest10from lemon_14_190918_æµè¯æ¡æ¶_unittest import test_ç»ä¹ ç¸å 0111from lemon_14_190918_æµè¯æ¡æ¶_unittest import test_ç»ä¹ ç¸å0212from lemon_14_190918_æµè¯æ¡æ¶_unittest.test_ç»ä¹ ç¸å 01 import TestAdd13from lemon_14_190918_æµè¯æ¡æ¶_unittest.test_ç»ä¹ ç¸å02 import TestMinus14# ä½¿ç¨ TestLoader 注éä¸é¢ç代ç 15cases = [TestAdd('test_add_success'),16 TestAdd('test_add_error'),17 TestMinus('test_add_success'),18 TestMinus('test_add_error')19 ]20# 1.åå§åæµè¯å¥ä»¶21suite = unittest.TestSuite(tests=cases)22'''23# 2.å¾å¥ä»¶éé¢æ·»å æµè¯ç¨ä¾24# addTestsä¸addTestçåºå«, 第ä¸ä¸ªå¯ä»¥æ·»å å¤ä¸ªï¼ç¬¬äºä¸ªåªè½æ·»å ä¸ä¸ª25# éè¦ä¸ä¸ªä¸ä¸ªå»æ·»å TestAddï¼ï¼ éé¢çæ¹æ³åï¼æ·»å å符串26# æ ¼å¼ï¼ç±»å称ï¼âæ¹æ³å称âï¼27"""28cases = [TestAdd('test_add_success'),29 TestAdd('test_add_error'),30 TestMinus('test_add_success'),31 TestMinus('test_add_error')32 ]33suite.addTests(cases)34"""35'''36# TestLoader ç¨æ¥å è½½æµè¯ç¨ä¾37# å¯ä»¥æ ¹æ®æ¨¡åå è½½ãæ ¹æ®æµè¯ç±»å è½½ãèªå·±å®ä¹è§åï¼è®©ä»ä»¬èªå¨åç°38loader = unittest.TestLoader()39# æ ¹æ®æµè¯ç±»å»å è½½æµè¯ç¨ä¾40cases = loader.loadTestsFromTestCase(TestAdd)41cases2 = loader.loadTestsFromTestCase(TestMinus)42cases3 = loader.loadTestsFromModule(test_ç»ä¹ ç¸å 01)43cases4 = loader.loadTestsFromModule(test_ç»ä¹ ç¸å02)44# åå§åæµè¯å¥ä»¶, å¾å¥ä»¶éé¢æ·»å æµè¯ç¨ä¾45suite = unittest.TestSuite()46suite.addTests(cases3)47suite.addTests(cases4)48# è¿è¡ , æµè¯æ¥åæ件, demo.txt49with open('demo.txt', 'w', encoding='utf-8') as f:50 # åå§å runner51 # stream æ件æµï¼å¯ä»¥ä¼ æ件52 # verbosity 详ç»ç¨åº¦53 runner = unittest.TextTestRunner(f, verbosity=0)54 # è¿è¡...
DeleteAddress.py
Source:DeleteAddress.py
...6class qgDeleteAddress(unittest.TestCase):7 def setUp(self):8 self.url = "/fgadmin/address/delete"9# æ·»å æ¶è´§å°åæå10 def test_add_success(self):11 user = {"id":77243286}12 result = SendHttp().run_http(self.url, "POST", user)13 print(result)14 self.assertEqual(result['code'], 200)15 self.assertEqual(result['message'], 'success')16# æ·»å æ¶è´§å°å失败ï¼å é¤çæ¶è´§å°åidä¸åå¨ï¼17 def test_add_success(self):18 user = {"id":000}19 result = SendHttp().run_http(self.url, "POST", user)20 print(result)21 self.assertEqual(result['code'], 400)22# æ·»å æ¶è´§å°å失败ï¼å é¤çæ¶è´§å°åidç±»åé误ï¼23 def test_add_success(self):24 user = {"id":"77243286"}25 result = SendHttp().run_http(self.url, "POST", user)26 print(result)27 self.assertEqual(result['code'], 400)28if __name__=='__main__':...
test_add.py
Source:test_add.py
...11 def setUp(self):#åç½®æ¡ä»¶12 # def __init__(self): #ç±»çåå§å13 self.b = Baiyue(s)14 self.b.login("byhy", "88888888")15 def test_add_success(self):16 name = random.randint(10, 100000)17 r = self.b.add(name).json()["ret"]18 self.assertEqual(r,0)19 # return r20 def test_add_name_error(self):21 name = random.randint(10, 100000)22 r = self.b.add("").json()["ret"]23 self.assertEqual(r, 0)24 # return r25 def test_add_name_null(self):26 name = random.randint(10, 100000)27 r = self.b.add(" ").json()["ret"]28 self.assertEqual(r, 0)29 # return r30if __name__ == '__main__':31 unittest.main()32# if __name__ == '__main__':33# t = Test_add()34# # r = t.test_add_success()35# # r = t.test_add_name_error()36# r = t.test_add_name_null()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!