Best Python code snippet using pytest-cov
engine.py
Source:engine.py
...23 setattr(obj, attr, copy.copy(backup))24 yield25 finally:26 setattr(obj, attr, backup)27def _ensure_topdir(meth):28 @functools.wraps(meth)29 def ensure_topdir_wrapper(self, *args, **kwargs):30 try:31 original_cwd = os.getcwd()32 except OSError:33 # Looks like it's gone, this is non-ideal because a side-effect will34 # be introduced in the tests here but we can't do anything about it.35 original_cwd = None36 os.chdir(self.topdir)37 try:38 return meth(self, *args, **kwargs)39 finally:40 if original_cwd is not None:41 os.chdir(original_cwd)42 return ensure_topdir_wrapper43class CovController(object):44 """Base class for different plugin implementations."""45 def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, config=None, nodeid=None):46 """Get some common config used by multiple derived classes."""47 self.cov_source = cov_source48 self.cov_report = cov_report49 self.cov_config = cov_config50 self.cov_append = cov_append51 self.cov_branch = cov_branch52 self.config = config53 self.nodeid = nodeid54 self.cov = None55 self.combining_cov = None56 self.data_file = None57 self.node_descs = set()58 self.failed_workers = []59 self.topdir = os.getcwd()60 self.is_collocated = None61 @contextlib.contextmanager62 def ensure_topdir(self):63 original_cwd = os.getcwd()64 os.chdir(self.topdir)65 yield66 os.chdir(original_cwd)67 @_ensure_topdir68 def pause(self):69 self.cov.stop()70 self.unset_env()71 @_ensure_topdir72 def resume(self):73 self.cov.start()74 self.set_env()75 @_ensure_topdir76 def set_env(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!!