Best Python code snippet using autotest_python
models.py
Source:models.py  
...89        else:90            iterations = []91            attributes = {}92        # grab test+host attributes from the host keyval93        attributes.update(cls.parse_host_keyval(job.dir, job.machine))94        if existing_instance:95            def constructor(*args, **dargs):96                existing_instance.__init__(*args, **dargs)97                return existing_instance98        else:99            constructor = cls100        return constructor(subdir, testname, status, reason, test_kernel,101                           job.machine, started_time, finished_time,102                           iterations, attributes, [])103    @classmethod104    def parse_partial_test(cls, job, subdir, testname, reason, test_kernel,105                           started_time):106        """Given a job and the basic metadata available when a test is107        started, create a test instance representing the partial result.108        Assume that since the test is not complete there are no results files109        actually available for parsing."""110        tko_utils.dprint("parsing partial test %s %s" % (subdir, testname))111        return cls(subdir, testname, "RUNNING", reason, test_kernel,112                   job.machine, started_time, None, [], {}, [])113    @staticmethod114    def load_attributes(keyval_path):115        """Load the test attributes into a dictionary from a test116        keyval path. Does not assume that the path actually exists."""117        if not os.path.exists(keyval_path):118            return {}119        return utils.read_keyval(keyval_path)120    @staticmethod121    def parse_host_keyval(job_dir, hostname):122        # the "real" job dir may be higher up in the directory tree123        job_dir = tko_utils.find_toplevel_job_dir(job_dir)124        if not job_dir:125            return {} # we can't find a top-level job dir with host keyvals126        # the keyval is <job_dir>/host_keyvals/<hostname> if it exists127        keyval_path = os.path.join(job_dir, "host_keyvals", hostname)128        if os.path.isfile(keyval_path):129            keyval = utils.read_keyval(keyval_path)130            return dict(("host-%s" % k, v) for k, v in keyval.iteritems())131        else:132            return {}133class patch(object):134    def __init__(self, spec, reference, hash):135        self.spec = spec...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!!
