Best Python code snippet using Testify_python
test_program.py
Source:test_program.py  
...145            "instance."146        ),147    )148    return parser149def parse_test_runner_command_line_args(plugin_modules, args):150    """Parse command line args for the TestRunner to determine verbosity and other stuff"""151    parser = default_parser()152    # Add in any additional options153    for plugin in plugin_modules:154        if hasattr(plugin, 'add_command_line_options'):155            plugin.add_command_line_options(parser)156    (options, args) = parser.parse_args(args)157    if (158            len(args) < 1 and159            not (160                options.rerun_test_file or161                options.replay_json or162                options.replay_json_inline163            )164    ):165        parser.error(166            'Test path required unless --rerun-test-file, --replay-json, or '167            '--replay-json-inline specified.'168        )169    test_path, module_method_overrides = _parse_test_runner_command_line_module_method_overrides(args)170    if options.list_suites:171        runner_action = ACTION_LIST_SUITES172    elif options.list_tests:173        runner_action = ACTION_LIST_TESTS174    else:175        runner_action = ACTION_RUN_TESTS176    test_runner_args = {177        'debugger': options.debugger,178        'suites_exclude': options.suites_exclude,179        'suites_require': options.suites_require,180        'failure_limit': options.failure_limit,181        'module_method_overrides': module_method_overrides,182        'options': options,183        'plugin_modules': plugin_modules184    }185    return runner_action, test_path, test_runner_args, options186def _parse_test_runner_command_line_module_method_overrides(args):187    """Parse a set of positional args (returned from an OptionParser probably)188    for specific modules or test methods.189    eg/ > python some_module_test.py SomeTestClass.some_test_method190    """191    test_path = args[0] if args else None192    module_method_overrides = defaultdict(set)193    for arg in args[1:]:194        module_path_components = arg.split('.')195        module_name = module_path_components[0]196        method_name = module_path_components[1] if len(module_path_components) > 1 else None197        if method_name:198            module_method_overrides[module_name].add(method_name)199        else:200            module_method_overrides[module_name] = None201    return test_path, module_method_overrides202class TestProgram(object):203    def __init__(self, command_line_args=None):204        """Initialize and run the test with the given command_line_args205            command_line_args will be passed to parser.parse_args206        """207        self.plugin_modules = load_plugins()208        command_line_args = command_line_args or sys.argv[1:]209        self.runner_action, self.test_path, self.test_runner_args, self.other_opts = parse_test_runner_command_line_args(210            self.plugin_modules,211            command_line_args212        )213        # allow plugins to modify test program214        for plugin_mod in self.plugin_modules:215            if hasattr(plugin_mod, "prepare_test_program"):216                plugin_mod.prepare_test_program(self.other_opts, self)217    def get_reporters(self, options, plugin_modules):218        reporters = []219        if options.disable_color:220            reporters.append(test_logger.ColorlessTextTestLogger(options))221        else:222            reporters.append(test_logger.TextTestLogger(options))223        for plugin in plugin_modules:...test_program_test.py
Source:test_program_test.py  
...23        """Make sure that when --rerun-test-file is passed,24        parse_test_runner_command_line_args doesn't complain about a missing25        test path.26        """27        test_program.parse_test_runner_command_line_args([], ['--rerun-test-file', '-'])28    def test_parse_test_runner_command_line_args_replay_json_inline(self):29        """Make sure that when --replay-json-inline is passed,30        parse_test_runner_command_line_args doesn't complain about a missing31        test path.32        """33        test_program.parse_test_runner_command_line_args([], ['--replay-json-inline', '{something that obviously isnt json}'])34    def test_parse_test_runner_command_line_args_replay_json(self):35        """Make sure that when --replay-json-inline is passed,36        parse_test_runner_command_line_args doesn't complain about a missing37        test path.38        """39        test_program.parse_test_runner_command_line_args([], ['--replay-json', 'somejsonfile.txt'])40    def test_parse_test_runner_command_line_args_no_test_path(self):41        """Make sure that if no options and no arguments are passed,42        parse_test_runner_command_line_args DOES complain about a missing test43        path.44        """45        with assert_raises(OptionParserErrorException):46            test_program.parse_test_runner_command_line_args([], [])47def test_call(command):48    proc = subprocess.Popen(command, stdout=subprocess.PIPE)49    stdout, stderr = proc.communicate()50    if proc.returncode:51        raise subprocess.CalledProcessError(proc.returncode, command)52    return stdout.strip().decode('UTF-8')53class TestifyRunAcceptanceTestCase(TestCase):54    expected_list = (55        'testing_suite.example_test ExampleTestCase.test_one\n'56        'testing_suite.example_test ExampleTestCase.test_two\n'57        'testing_suite.example_test SecondTestCase.test_one'58    )59    expected_tests = 'PASSED.  3 tests'60    def test_help(self):...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!!
