Best Python code snippet using pytest
instantiate_templates.py
Source:instantiate_templates.py
...99 (head, tail) = os.path.split(path)100 if head == "":101 return tail102 else:103 return module_name_from_path(head) + "." + tail104def module_name_from_path(path):105 '''Compute the fully qualified name of a module from the path of its .qll[t]106 file. The path should be relative to the library root.'''107 (module_root, ext) = os.path.splitext(path)108 return module_name_from_path_impl(module_root)109def main():110 templates = {}111 root = sys.argv[1]112 for template_path in glob.glob(os.path.join(root, "**\\*.qllt"), recursive = True):113 print(template_path)114 module_name = module_name_from_path(os.path.relpath(template_path, root))115 print(module_name)116 template = read_template(template_path, module_name)117 templates[template["name"]] = template118 for name, template in templates.items():119 if "template_def" in template:120 generate_instantiations(template, root, templates)121if __name__ == "__main__":...
utils.py
Source:utils.py
...61 """62 finder = TestFileFinder()63 os.path.walk( from_dir, finder.visit, test_prefix )64 return finder.files65def module_name_from_path( path ):66 """67 Return the dotted module name matching the filesystem path.68 """69 assert path.endswith( '.py' )70 path = path[:-3]71 path = path[ len(product_prefix) + 1: ] # strip extraneous crap72 dirs = []73 while path:74 path, end = os.path.split( path )75 dirs.insert( 0, end )76 return ".".join( dirs )77def get_suite( file ):78 """79 Retrieve a TestSuite from 'file'.80 """81 module_name = module_name_from_path( file )82 loader = unittest.defaultTestLoader83 try:84 suite = loader.loadTestsFromName( '%s.test_suite' % module_name )85 except AttributeError:86 try:87 suite = loader.loadTestsFromName( module_name )88 except ImportError, err:89 print "Error importing %s\n%s" % (module_name, err)90 raise91 return suite92def allTests( from_dir=product_dir, test_prefix='test' ):93 """94 Walk the product and build a unittest.TestSuite aggregating tests.95 """...
ci_runner.py
Source:ci_runner.py
...68 setup_environment(env_file, role=aws_assume_role_arn)69 except FileNotFoundError:70 LOG.warning("Environment file %s doesn't exit", env_file)71 # module name is parent directory72 mod = module_name or module_name_from_path(modules_path)73 LOG.info("Processing module %s", mod)74 status = {mod: run_job(osp.join(modules_path), action)}75 outputs = terraform_output(osp.join(modules_path))76 if "github_token" in outputs:77 LOG.info(78 "Setting GITHUB_TOKEN and TF_VAR_github_token environment variable from module outputs."79 )80 environ["GITHUB_TOKEN"] = outputs["github_token"]["value"]81 environ["TF_VAR_github_token"] = outputs["github_token"]["value"]82 if status[mod]["success"]:83 LOG.info("%s success: %s", mod, status[mod]["success"])84 else:85 LOG.error("Failed to process %s", mod)86 LOG.error("STDOUT: %s", status[mod]["stdout"].decode("utf-8"))...
test_basic.py
Source:test_basic.py
...49 if spath.endswith("__init__.py"):50 continue51 if ".ipynb_checkpoints" in spath:52 continue53 name = module_name_from_path(path, tgtdir_len)54 modules.append((path, name))55 return modules56def module_name_from_path(p, n):57 # strip leading target dir and separator58 s = str(p)[n + 1:]59 # strip ext60 s = s[:-3]61 # change separator to .62 s = s.replace(sep, ".")63 return s64def import_python_file(file_path, module_name):65 spec = importlib.util.spec_from_file_location(module_name, file_path)66 module = importlib.util.module_from_spec(spec)67 sys.modules[module_name] = module...
Looking for an in-depth tutorial around pytest? LambdaTest covers the detailed pytest tutorial that has everything related to the pytest, from setting up the pytest framework to automation testing. Delve deeper into pytest testing by exploring advanced use cases like parallel testing, pytest fixtures, parameterization, executing multiple test cases from a single file, and more.
Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.
https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP
Get 100 minutes of automation test minutes FREE!!