Best Python code snippet using tox_python
__init__.py
Source:__init__.py
...157 else:158 if self.config.option.showconfig:159 self.showconfig()160 elif self.config.option.listenvs:161 self.showenvs(all_envs=False, description=show_description)162 elif self.config.option.listenvs_all:163 self.showenvs(all_envs=True, description=show_description)164 else:165 with self.cleanup():166 return self.subcommand_test()167 @contextmanager168 def cleanup(self):169 self.config.temp_dir.ensure(dir=True)170 try:171 yield172 finally:173 self.hook.tox_cleanup(session=self)174 def subcommand_test(self):175 if self.config.skipsdist:176 reporter.info("skipping sdist step")177 else:178 for venv in self.venv_dict.values():179 if not venv.envconfig.skip_install:180 venv.package = self.hook.tox_package(session=self, venv=venv)181 if not venv.package:182 return 2183 venv.envconfig.setenv[str("TOX_PACKAGE")] = str(venv.package)184 if self.config.option.sdistonly:185 return186 within_parallel = PARALLEL_ENV_VAR_KEY in os.environ187 try:188 if not within_parallel and self.config.option.parallel != PARALLEL_OFF:189 run_parallel(self.config, self.venv_dict)190 else:191 run_sequential(self.config, self.venv_dict)192 finally:193 retcode = self._summary()194 return retcode195 def _add_parallel_summaries(self):196 if self.config.option.parallel != PARALLEL_OFF and "testenvs" in self.resultlog.dict:197 result_log = self.resultlog.dict["testenvs"]198 for tox_env in self.venv_dict.values():199 data = self._load_parallel_env_report(tox_env)200 if data and "testenvs" in data and tox_env.name in data["testenvs"]:201 result_log[tox_env.name] = data["testenvs"][tox_env.name]202 @staticmethod203 def _load_parallel_env_report(tox_env):204 """Load report data into memory, remove disk file"""205 result_json_path = tox_env.get_result_json_path()206 if result_json_path and result_json_path.exists():207 with result_json_path.open("r") as file_handler:208 data = json.load(file_handler)209 result_json_path.remove()210 return data211 def _summary(self):212 is_parallel_child = PARALLEL_ENV_VAR_KEY in os.environ213 if not is_parallel_child:214 reporter.separator("_", "summary", reporter.Verbosity.QUIET)215 exit_code = 0216 for venv in self.venv_dict.values():217 report = reporter.good218 status = getattr(venv, "status", "undefined")219 if isinstance(status, tox.exception.InterpreterNotFound):220 msg = " {}: {}".format(venv.envconfig.envname, str(status))221 if self.config.option.skip_missing_interpreters == "true":222 report = reporter.skip223 else:224 exit_code = 1225 report = reporter.error226 elif status == "platform mismatch":227 msg = " {}: {} ({!r} does not match {!r})".format(228 venv.envconfig.envname, str(status), sys.platform, venv.envconfig.platform229 )230 report = reporter.skip231 elif status and status == "ignored failed command":232 msg = " {}: {}".format(venv.envconfig.envname, str(status))233 elif status and status != "skipped tests":234 msg = " {}: {}".format(venv.envconfig.envname, str(status))235 report = reporter.error236 exit_code = 1237 else:238 if not status:239 status = "commands succeeded"240 msg = " {}: {}".format(venv.envconfig.envname, status)241 if not is_parallel_child:242 report(msg)243 if not exit_code and not is_parallel_child:244 reporter.good(" congratulations :)")245 path = self.config.option.resultjson246 if path:247 if not is_parallel_child:248 self._add_parallel_summaries()249 path = py.path.local(path)250 data = self.resultlog.dumps_json()251 reporter.line("write json report at: {}".format(path))252 path.write(data)253 return exit_code254 def showconfig(self):255 show_config(self.config)256 def showenvs(self, all_envs=False, description=False):...
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!!