Best Python code snippet using slash
suite.py
Source:suite.py
...61 if self._slashconf is None:62 self._slashconf = File(self, relpath='slashconf.py')63 return self._slashconf64 @property65 def slashrc(self):66 if self._slashrc is None:67 self._slashrc = File(self, relpath='.slashrc')68 return self._slashrc69 def add_test(self, type=None, file=None): # pylint: disable=unused-argument70 if type is None:71 type = self.strategy.get_test_type()72 if type == 'function':73 returned = self.add_function_test()74 elif type == 'method':75 returned = self.add_method_test()76 else:77 raise NotImplementedError('Unknown test type {!r}'.format(type)) # pragma: no cover78 assert returned in self._notified79 return returned80 def add_method_test(self):81 cls = self.strategy.get_class_for_test(82 self.strategy.get_file_for_test(self))83 return cls.add_method_test()84 def add_function_test(self):85 return self.strategy.get_file_for_test(self).add_function_test()86 def notify_test_added(self, test):87 self._notified.append(test)88 if test.is_method_test():89 self._num_method_tests += 190 else:91 self._num_function_tests += 192 def add_file(self):93 returned = File(self)94 self._files.append(returned)95 return returned96 def get_last_file(self):97 if not self._files:98 return None99 return self._files[-1]100 def __len__(self):101 return len(self._notified)102 def __getitem__(self, idx):103 return self._notified[idx]104 def run(self, verify=True, expect_interruption=False, additional_args=(), args=None, commit=True, sort=True, num_workers=1,105 expect_session_errors=False):106 if commit:107 self.commit()108 path = self._last_committed_path109 assert path is not None110 report_stream = StringIO()111 returned = SlashRunResult(report_stream=report_stream)112 captured = []113 if args is None:114 args = [path]115 args.extend(additional_args)116 if self.is_parallel:117 args.extend(['--parallel', str(num_workers), '-vvvvv', '--parallel-addr', 'localhost'])118 with self._capture_events(returned), self._custom_sorting(sort):119 with self._custom_slashrc(path):120 app = slash_run(121 munch.Munch(argv=args, cmd="run"), report_stream=report_stream,122 app_callback=captured.append,123 )124 returned.exit_code = app.exit_code125 if app.interrupted:126 assert expect_interruption, 'Unexpectedly interrupted'127 else:128 assert not expect_interruption, 'Session was not interrupted as expected'129 if captured:130 assert len(captured) == 1131 returned.session = captured[0].session132 assert not returned.session.has_internal_errors(), 'Session has internal errors!'133 if verify:134 validate_run(self, returned, expect_interruption=expect_interruption, expect_session_errors=expect_session_errors)135 return returned136 @contextmanager137 def _custom_sorting(self, do_sort):138 @gossip.register('slash.tests_loaded')139 def tests_loaded(tests):140 if do_sort:141 for test in tests:142 if not test.__slash__.is_interactive():143 test.__slash__.set_sort_key(int(self._get_test_id_from_runnable(test)))144 try:145 yield146 finally:147 tests_loaded.gossip.unregister()148 def _get_test_id_from_runnable(self, test):149 return get_test_id_from_test_address(test.__slash__.address)150 @contextmanager151 def _custom_slashrc(self, path):152 if self._slashrc is not None:153 slashrc_path = os.path.join(path, self._slashrc.get_relative_path())154 else:155 slashrc_path = None156 with get_temporary_slashrc_context(slashrc_path):157 yield158 @contextmanager159 def _capture_events(self, summary):160 sys.modules['__ut__'] = summary.tracker161 try:162 yield163 finally:164 sys.modules.pop('__ut__')165 def commit(self):...
test_site_customization.py
Source:test_site_customization.py
...36 global _customization_index37 returned = "import {0}; {0}._apply_customization({1})".format(__name__, _customization_index)38 _customization_index += 139 return returned40 def test_customize_via_local_and_global_slashrc(self):41 self._test_customize_via_local_slashrc(also_use_global=True)42 def test_customize_via_local_slashrc(self):43 self._test_customize_via_local_slashrc(also_use_global=False)44 def _test_customize_via_local_slashrc(self, also_use_global):45 if also_use_global:46 global_slashrc_path = os.path.join(self.get_new_path(), "slashrc")47 self.override_config("run.user_customization_file_path", global_slashrc_path)48 with open(global_slashrc_path, "w") as f:49 f.write(self.get_customization_source())50 new_path = self.get_new_path()51 self.addCleanup(os.chdir, os.path.abspath("."))52 os.chdir(new_path)53 with open(".slashrc", "w") as f:54 f.write(self.get_customization_source())55 self.assert_customization_loaded()56 def test_customize_via_env_var(self):57 os.environ["SLASH_SETTINGS"] = custom_filename = mktemp()58 self.addCleanup(os.environ.pop, "SLASH_SETTINGS")...
test_project_customization.py
Source:test_project_customization.py
1# pylint: disable=redefined-outer-name,unused-argument,unused-variable,undefined-variable2import pytest3def test_plugin_activation_forcing_via_activate(customized_suite, suite_test):4 @customized_suite.slashrc.include5 def __code__():6 slash.plugins.manager.activate('custom')7 result = customized_suite.run().session.results.global_result8 assert result.data['customized']9def test_plugin_activation_deactivate_via_commandline(customized_suite, suite_test):10 @customized_suite.slashrc.include11 def __code__():12 slash.plugins.manager.activate_later('custom')13 result = customized_suite.run(additional_args=['--without-custom']).session.results.global_result14 assert 'customized' not in result.data15def test_plugin_activation_from_configure_hook(customized_suite, suite_test):16 @customized_suite.slashrc.include17 def __code__():18 @slash.hooks.configure.register19 def configure_hook():20 slash.plugins.manager.activate_later('custom')21 result = customized_suite.run().session.results.global_result22 assert 'customized' in result.data23def test_plugin_deactivation_override_configure_hook(customized_suite, suite_test):24 @customized_suite.slashrc.include25 def __code__():26 @slash.hooks.configure.register27 def configure_hook():28 slash.plugins.manager.activate_later('custom')29 result = customized_suite.run(additional_args=['--without-custom']).session.results.global_result30 assert 'customized' not in result.data31def test_configure_hook_depends_on_configuration_cmdline(customized_suite, suite_test):32 @customized_suite.slashrc.include33 def __code__():34 slash.config.extend({35 'some_config': 1 // slash.conf.Cmdline(arg='--some-config'),36 })37 @slash.hooks.configure.register38 def configure_hook():39 assert slash.config.root.some_config == 100040 result = customized_suite.run(additional_args=['--some-config=1000']).session.results.global_result41@pytest.fixture42def customized_suite(suite):43 @suite.slashrc.include44 def __code__():45 class CustomPlugin(slash.plugins.PluginInterface):46 def get_name(self):47 return 'custom'48 def session_start(self):49 slash.session.results.global_result.data['customized'] = True50 slash.plugins.manager.install(CustomPlugin())...
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!!