Best Python code snippet using autotest_python
main.py
Source:main.py  
...47    """48        Empty class. But will be populated with test cases during runtime49    """50    pass51def set_tests(tests=''):52    """53        Sets the gluster_tests Test class with the test cases.54        Name of the tests will be prepended with test_ to enable55        unittest to recognise them as test case56    """57    if tests == '':58        tests = testcases.keys()59    if test_list == {}:60        test_list[''] = testcases.keys()61    i = 062    for voltype, vol_tests in test_list.iteritems():63        for test in vol_tests:64            if test in tests:65                if test not in test_mounts:66                    test_mounts[test] = ['']67                for mount in test_mounts[test]:68                    try:69                        setattr(gluster_tests, "test_%d_%s_%s_%s" % \70                                (i, voltype, mount, test), testcases[test])71                        i = i + 172                        test_seq.append((voltype, mount))73                    except KeyError:74                        sys.stderr.write("Unable to find test %s." \75                                         "Skipping...\n" % test)76def main():77    parser = argparse.ArgumentParser()78    parser.add_argument("-t", help="Test case(s) to run")79    parser.add_argument("-d", help="Directory to choose tests from")80    parser.add_argument("-f", help="Find the test cases from the file")81    parser.add_argument("-c", help="The (yaml) config file to use",82                              default="config.yml")83    parser.add_argument("-j", help="Directory to store JUnit XML file",84                              action="store",85                              dest="xmldir")86    args = parser.parse_args()87    _ = distaf_init(args.c)88    if args.f != None:89        collect_tests(args.f)90        set_tests()91    elif args.d != None and args.t != None:92        collect_tests("tests_d/%s" % args.d)93        set_tests(args.t.split(' '))94    elif args.t != None:95        collect_tests()96        set_tests(args.t.split(' '))97    elif args.d != None:98        collect_tests("tests_d/%s" % args.d)99        set_tests()100    else:101        collect_tests()102        set_tests()103    get_num = lambda x: int(re.search(r'test_([0-9]+)_', x).group(1))104    sortcmp = lambda _, x, y: cmp(get_num(x), get_num(y))105    unittest.TestLoader.sortTestMethodsUsing = sortcmp106    if args.xmldir != None:107        import xmlrunner108        runner = xmlrunner.XMLTestRunner(output=args.xmldir)109    else:110        runner = unittest.TextTestRunner(verbosity=2)111    itersuite = unittest.TestLoader().loadTestsFromTestCase(gluster_tests)112    runner.run(itersuite)113    distaf_finii()114if __name__ == '__main__':...service_uno_test.py
Source:service_uno_test.py  
...10class ModuleService(Service):11    async def gain_focus(self):12        await super().gain_focus()13        await self.run_test()14    def set_tests(self,xmit):15        return [ xmit.set_cursor_on, xmit.set_cursor_off,16                  xmit.set_blink_cursor_on, xmit.set_blink_cursor_off,17                  xmit.set_cursor_off,18                  xmit.set_backlight_off, xmit.set_backlight_on,19                  xmit.set_display_off, xmit.set_display_on,20                  xmit.blink_slow, xmit.blink_fast, xmit.blink_off21            ]22        23    async def run_test(self):24        while True:25            xmit = xmit_lcd.XmitLcd(fr=self.name).clear_screen()26            xmit.set_msg("â¶ press any key" + "\nâ· to start tests")27            await self.put_to_output_q(xmit)28            29            tests_len = len(self.set_tests(xmit))30            lcd_col_cnt = self.get_parm("lcd_col_cnt",16)31            await self.await_ir_input()32            i = 033            while i < tests_len:34                xmit = xmit_lcd.XmitLcd(fr=self.name).clear_screen()35                36                test = self.set_tests(xmit)[i]37                test_name = str(test.__name__)38                format_str = "â´ {0: <"+str(lcd_col_cnt-2)+"}"39                prompt = format_str.format(test_name)[:lcd_col_cnt-1]+"âµ\n"40                xmit.set_msg(prompt)41                test() # actually execute the test - added to xmit42                    43                await self.put_to_output_q(xmit)44                45                # prevent up/down arrows from leaving display: control_keys=None46                key = (await self.await_ir_input(control_keys=None)).get_msg()47                48                if key == "â´":49                    i -= 150                    if i < 0:...app_test.py
Source:app_test.py  
1import unittest2from tests.table_tests import NFTServerCreateTableTests3from tests.table_tests import NFTServerListTableTests4from tests.table_tests import NFTServerDeleteTableTests5from tests.chain_tests import NFTServerCreateChainTests6from tests.chain_tests import NFTServerListChainTests7from tests.chain_tests import NFTServerDeleteChainTests8from tests.rule_tests import NFTServerCreateRuleTests9from tests.rule_tests import NFTServerListRuleTests10from tests.rule_tests import NFTServerDeleteRuleTests11from tests.set_tests import NFTServerCreateSetTests12from tests.set_tests import NFTServerListSetTests13from tests.set_tests import NFTServerUpdateSetTests14from tests.dictionary_tests import NFTServerCreateDictionaryTests15from tests.dictionary_tests import NFTServerListDictionaryTests16from tests.dictionary_tests import NFTServerUpdateDictionaryTests17if __name__ == '__main__':...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!!
