Best Python code snippet using slash
charm.py
Source:charm.py
...188 "hostPath": {"path": hostpath_folder, "type": "Directory"},189 }190 )191 container["command"] = ["/osm-debug-scripts/debug.sh"]192 def _debug_if_needed(self, pod_spec):193 """194 Debug the pod_spec if needed195 :params: pod_spec: Pod Spec to be debugged.196 """197 if self.debug_mode_enabled:198 if not self.debug_pubkey:199 raise Exception("debug_pubkey config is not set")200 self._debug(pod_spec)201 def _get_build_pod_spec_kwargs(self):202 """Get kwargs for the build_pod_spec function"""203 kwargs = {}204 if self.mysql_uri:205 kwargs["mysql_config"] = MysqlModel(**self.config)206 return kwargs207 def configure_pod(self, _=None) -> NoReturn:208 """Assemble the pod spec and apply it, if possible."""209 try:210 if self.unit.is_leader():211 self.unit.status = MaintenanceStatus("Assembling pod spec")212 image_info = self.image.fetch()213 kwargs = self._get_build_pod_spec_kwargs()214 pod_spec = self.build_pod_spec(image_info, **kwargs)215 self._debug_if_needed(pod_spec)216 self._set_pod_spec(pod_spec)217 self.unit.status = ActiveStatus("ready")218 except OCIImageResourceError:219 self.unit.status = BlockedStatus("Error fetching image information")220 except ValidationError as e:221 logger.error(f"Config data validation error: {e}")222 logger.debug(traceback.format_exc())223 self.unit.status = BlockedStatus(str(e))224 except RelationsMissing as e:225 logger.error(f"Relation missing error: {e.message}")226 logger.debug(traceback.format_exc())227 self.unit.status = BlockedStatus(e.message)228 except ModelError as e:229 self.unit.status = BlockedStatus(str(e))...
test_running.py
Source:test_running.py
...91 summary = suite.run(additional_args=['-x'])92 for test in suite.iter_all_after(suite_test):93 for res in summary.get_all_results_for_test(test):94 assert res.is_success()95def test_debug_if_needed(request, config_override, suite, suite_test):96 suite_test.when_run.fail()97 debugged = {'value': False}98 def _debug_if_needed(exc_info): # pylint: disable=unused-argument99 debugged['value'] = True100 # pylint: disable=protected-access101 request.addfinalizer(functools.partial(102 setattr, slash.utils.debug, '_KNOWN_DEBUGGERS', slash.utils.debug._KNOWN_DEBUGGERS))103 slash.utils.debug._KNOWN_DEBUGGERS = [_debug_if_needed]104 config_override('debug.enabled', True)105 suite.run()106 assert debugged['value']107@pytest.fixture(params=['raising', 'adding'])108def fatal_error_adder(request, failure_type):109 def adder(test):110 if request.param == 'raising':111 test.append_line(112 'from slash.exception_handling import mark_exception_fatal')...
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!!