Package: pydatatest
PyDataTestData driven python test frameworkDocumentIntroductionAim to provide a simple way to write testcase, especially when test same logic with different data input and output. So PyDataTest wrap unittest with a set of utilities to test with data.Installpipinstallpydatatest# with pippoetryaddpydatatest# or with poetrypipenvaddpydatatest# with pipenvUsageGet a runner instancerunner=pydatatest.runner()Write a test case and inject data including input and outputdata=[["abc","123"],['aaa',"000000"]]@inject_def(['passport','password'],session=True)@test_with(runner)# Register this testcase, also can use runner name, eg: @test_with("runner1")classTestUserLogin(PyDataTestCase):defsetUp(self):print("login test start\n")@inject(["abc","123456"])deftest_01(self):self.assertEqual(self.passport,'hitest')@inject(data,True)deftest_02(self):self.assertEqual(self.password,'111111')deftearDown(self):print("login test end\n")Run with PyDataTestrunner.run()APIrunnerA framework instance that will run all testcasesExample:r=pydatatest.runner("my runner")r.add_test(testcase)# add a test case manuallyr.run()# start testPyDataTestCaseData test InstanceAttributes:session: request session, can be used in many test method to share some stateinjected variables: You can access it in your test method as self.variable_name(the name is as defined in your @inject_def)Methods:before_all: run before all casesafter_all: run after all casesbefore_each: run before all run of every test methodafter_each: run before all run of every test methodbefore_each_data: run before every run of every test methodafter_each_data: run after every run of every test methodtest**: test case method, each method will be run several times accoding to the injected dataYou can also use the unittest api here, such as self.assertEqual, for more information, seeAssert methodsandunittestExample:@inject_def(['passport','password'],session=True)@test_with(myrunner)classTestUserLogin(PyDataTestCase):@classmethoddefbefore_all(cls):print("before all test")@classmethoddefafter_all(cls):print("after all test")defbefore_each(self):print("before_each test")defafter_each(self):print("after_each test")defbefore_each_data(self):print("before_each_data test")defafter_each_data(self):print("after_each_data test")@inject(data[0])deftest_01(self):self.assertEqual(self.passport,'username')@inject(data,multi=True)deftest_02(self):print(self.passport)print(self.password)self.assertEqual(self.password,'password')@inject(["username","password1"])deftest_03(self):self.assertEqual(self.password,'password')@test_withRegister a testcaseParams:runner: string or runner instance, you can use runner name to avoid loop dependency@inject_def and @injectExample：@inject_def(['passport','password'],session=True)classTestCaseClass(PyDataTestCase):@inject(["passport1","password1"])deftest_01(self):print(self.passport)# defined variable can be access here@inject_defDefine inject data varibales
Params:variables: injected data will be parsed according to the sequence of variablessession: if True means that this case will use request session@injectInject data to a test methodParams:data: list like data, will be parsed according to its sequence (same as@inject_def)multi: if true, the data will be seen as list of many group of variable, and this test method will be run the same times as the length of the data. Each group of variable will be run once.TODO@depends_on: to run multicase pipeline automatically@inject_yaml: to inject yaml data@inject_csv: to inject csv data@once: indicates that the test case should be run once@expected: indicates that the test case should return expected output@throws: indicates that the test case should throw specific exceptionMore corner case