How to use matches_with_reason method in tox

Best Python code snippet using tox_python

venv.py

Source:venv.py Github

copy

Full Screen

...64 alwayscopy,65 )66 except Exception:67 return None68 def matches_with_reason(self, other, deps_matches_subset=False):69 for attr in (70 "base_resolved_python_md5",71 "base_resolved_python_path",72 "tox_version",73 "sitepackages",74 "usedevelop",75 "alwayscopy",76 ):77 left = getattr(self, attr)78 right = getattr(other, attr)79 if left != right:80 return False, "attr {} {!r}!={!r}".format(attr, left, right)81 self_deps = set(self.deps)82 other_deps = set(other.deps)83 if self_deps != other_deps:84 if deps_matches_subset:85 diff = other_deps - self_deps86 if diff:87 return False, "missing in previous {!r}".format(diff)88 else:89 return False, "{!r}!={!r}".format(self_deps, other_deps)90 return True, None91 def matches(self, other, deps_matches_subset=False):92 outcome, _ = self.matches_with_reason(other, deps_matches_subset)93 return outcome94class VirtualEnv(object):95 def __init__(self, envconfig=None, session=None):96 self.envconfig = envconfig97 self.session = session98 @property99 def hook(self):100 return self.envconfig.config.pluginmanager.hook101 @property102 def path(self):103 """ Path to environment base dir. """104 return self.envconfig.envdir105 @property106 def path_config(self):107 return self.path.join(".tox-config1")108 @property109 def name(self):110 """ test environment name. """111 return self.envconfig.envname112 def __repr__(self):113 return "<VirtualEnv at {!r}>".format(self.path)114 def getcommandpath(self, name, venv=True, cwd=None):115 """ Return absolute path (str or localpath) for specified command name.116 - If it's a local path we will rewrite it as as a relative path.117 - If venv is True we will check if the command is coming from the venv118 or is whitelisted to come from external.119 """120 name = str(name)121 if os.path.isabs(name):122 return name123 if os.path.split(name)[0] == ".":124 path = cwd.join(name)125 if path.check():126 return str(path)127 if venv:128 path = self._venv_lookup_and_check_external_whitelist(name)129 else:130 path = self._normal_lookup(name)131 if path is None:132 raise tox.exception.InvocationError("could not find executable {!r}".format(name))133 return str(path) # will not be rewritten for reporting134 def _venv_lookup_and_check_external_whitelist(self, name):135 path = self._venv_lookup(name)136 if path is None:137 path = self._normal_lookup(name)138 if path is not None:139 self._check_external_allowed_and_warn(path)140 return path141 def _venv_lookup(self, name):142 return py.path.local.sysfind(name, paths=[self.envconfig.envbindir])143 def _normal_lookup(self, name):144 return py.path.local.sysfind(name)145 def _check_external_allowed_and_warn(self, path):146 if not self.is_allowed_external(path):147 self.session.report.warning(148 "test command found but not installed in testenv\n"149 " cmd: {}\n"150 " env: {}\n"151 "Maybe you forgot to specify a dependency? "152 "See also the whitelist_externals envconfig setting.".format(153 path, self.envconfig.envdir154 )155 )156 def is_allowed_external(self, p):157 tryadd = [""]158 if tox.INFO.IS_WIN:159 tryadd += [os.path.normcase(x) for x in os.environ["PATHEXT"].split(os.pathsep)]160 p = py.path.local(os.path.normcase(str(p)))161 for x in self.envconfig.whitelist_externals:162 for add in tryadd:163 if p.fnmatch(x + add):164 return True165 return False166 def update(self, action):167 """ return status string for updating actual venv to match configuration.168 if status string is empty, all is ok.169 """170 rconfig = CreationConfig.readconfig(self.path_config)171 if self.envconfig.recreate:172 reason = "-r flag"173 else:174 if rconfig is None:175 reason = "no previous config {}".format(self.path_config)176 else:177 live_config = self._getliveconfig()178 deps_subset_match = getattr(self.envconfig, "deps_matches_subset", False)179 outcome, reason = rconfig.matches_with_reason(live_config, deps_subset_match)180 if reason is None:181 action.info("reusing", self.envconfig.envdir)182 return183 action.info("cannot reuse", reason)184 if rconfig is None:185 action.setactivity("create", self.envconfig.envdir)186 else:187 action.setactivity("recreate", self.envconfig.envdir)188 try:189 self.hook.tox_testenv_create(action=action, venv=self)190 self.just_created = True191 except tox.exception.UnsupportedInterpreter as exception:192 return exception193 try:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful