Best Python code snippet using slash
test_parallel.py
Source:test_parallel.py
...380 for index in range(len(tests)):381 worker.exclude_test(index)382 if num_workers == 1:383 summary = parallel_suite.run(num_workers=num_workers, verify=False)384 assert summary.session.results.get_num_started() == 0385 else:386 summary = parallel_suite.run(num_workers=num_workers)387 assert summary.session.results.is_success()388@pytest.mark.parametrize('use_test_index', [True, False])389def test_exclude_test_on_all_workers_causes_timeout(parallel_suite, config_override, use_test_index):390 config_override("parallel.no_request_timeout", 2)391 @slash.hooks.tests_loaded.register # pylint: disable=no-member, unused-argument392 def tests_loaded(tests): # pylint: disable=unused-variable, unused-argument393 if slash.utils.parallel_utils.is_parent_session():394 from slash import ctx395 for worker in ctx.session.parallel_manager.workers.values():396 if use_test_index:397 worker.exclude_test(0)398 else:399 worker.exclude_test(tests[0])400 summary = parallel_suite.run(num_workers=2, verify=False)401 assert summary.session.results.get_num_started() == len(parallel_suite) - 1402 assert not summary.get_all_results_for_test(parallel_suite[0])403def test_exclude_and_force_on_same_worker_raises_runtime_err(parallel_suite):404 @slash.hooks.tests_loaded.register # pylint: disable=no-member, unused-argument405 def tests_loaded(tests): # pylint: disable=unused-variable, unused-argument406 if slash.utils.parallel_utils.is_parent_session():407 from slash import ctx408 worker = list(ctx.session.parallel_manager.workers.values())[0]409 worker.exclude_test(0)410 worker.force_test(0)411 summary = parallel_suite.run(num_workers=2, verify=False)...
result.py
Source:result.py
...309 """310 return any(result.is_interrupted() for result in self._iterator())311 def get_num_results(self):312 return len(self._results_dict)313 def get_num_started(self):314 return self._count(Result.is_started, include_global=False)315 def get_num_successful(self):316 return self._count(Result.is_success_finished, include_global=False)317 def get_num_errors(self):318 return self._count(Result.is_error)319 def get_num_failures(self):320 return self._count(Result.is_just_failure)321 def get_num_skipped(self, include_not_run=True):322 if include_not_run:323 return self._count(Result.is_skip)324 return self._count(Result.is_run_and_skip)325 def get_num_not_run(self):326 return self._count(Result.is_not_run, include_global=False)327 def has_fatal_errors(self):...
test_slash_resume.py
Source:test_slash_resume.py
...22 if index > fail_index:23 test.expect_not_run()24 result = suite.run(additional_args=['-x'])25 resumed = get_tests_from_previous_session(result.session.id)26 assert len(resumed) + result.session.results.get_num_started() - 1 == len(suite)27def test_resume_with_filter(suite, config_override):28 fail_index = len(suite) // 229 suite[fail_index].when_run.fail()30 for test in suite[fail_index + 1:]:31 test.expect_not_run()32 result = suite.run(additional_args=['-x'])33 resumed = get_tests_from_previous_session(result.session.id)34 filtered_out_test_name = resumed[0].address_in_file35 with slash.Session():36 config_override('run.filter_strings', [f'not {filtered_out_test_name}'])37 tests = slash.loader.Loader().get_runnables(resumed)38 assert filtered_out_test_name not in [test.__slash__.address_in_file for test in tests]39def test_resume_with_parametrization(suite, suite_test):40 num_values1 = 341 num_values2 = 542 suite_test.add_parameter(num_values=num_values1)43 suite_test.add_parameter(num_values=num_values2)44 fail_index = len(suite) // 245 suite[fail_index].when_run.fail()46 summary = suite.run()47 resumed = get_tests_from_previous_session(summary.session.id)48 assert len(summary.get_all_results_for_test(suite_test)) == num_values1 * num_values249 assert len(resumed) == 150 assert resumed[0].address_in_file == address_in_file(suite[fail_index])51def test_different_folder_no_resume_session_id(suite, tmpdir): # pylint: disable=unused-argument52 fail_index = len(suite) // 253 suite[fail_index].when_run.fail()54 suite.run()55 sessoin_id = get_last_resumeable_session_id()56 assert sessoin_id57 with tmpdir.ensure_dir().as_cwd():58 with pytest.raises(CannotResume):59 sessoin_id = get_last_resumeable_session_id()60def test_delete_old_sessions(suite, config_override):61 result = suite.run()62 assert result.session.id == get_last_resumeable_session_id()63 config_override('resume.state_retention_days', 0)64 result = suite.run()65 with pytest.raises(CannotResume):66 get_last_resumeable_session_id()67def test_failed_and_unstarted_first_fails(suite, config_override):68 config_override('resume.failed_first', True)69 config_override('resume.unstarted_first', True)70 result = suite.run()71 with pytest.raises(CannotResume):72 get_tests_from_previous_session(result.session.id)73@pytest.mark.parametrize('failed_first', [True, False])74def test_failed_first_or_unstarted_first(suite, failed_first, config_override):75 fail_index = len(suite) // 276 skip_index = fail_index - 177 suite[skip_index].when_run.skip()78 suite[fail_index].when_run.fail()79 for index, test in enumerate(suite):80 if index > fail_index:81 test.expect_not_run()82 result = suite.run(additional_args=['-x'])83 regular_order = get_tests_from_previous_session(result.session.id)84 if failed_first:85 config_override('resume.failed_first', True)86 else:87 config_override('resume.unstarted_first', True)88 order_after_changing_config = get_tests_from_previous_session(result.session.id)89 assert len(order_after_changing_config) + result.session.results.get_num_started() - 2 == len(suite)90 first_test_in_resumed_suite = fail_index if failed_first else skip_index91 assert order_after_changing_config[0].address_in_file == address_in_file(suite[first_test_in_resumed_suite])92 if failed_first:93 assert regular_order[1] == order_after_changing_config[0]94 assert regular_order[0] == order_after_changing_config[1]95 assert regular_order[2:] == order_after_changing_config[2:]96 else:97 failed_test = order_after_changing_config.pop(len(order_after_changing_config)-1)98 order_after_changing_config.insert(1, failed_test)99 assert regular_order == order_after_changing_config100@pytest.mark.parametrize('failed_first', [True, False])101def test_failed_or_unstarted_with_no_such_tests(suite, failed_first, suite_test, config_override):102 if failed_first:103 suite_test.when_run.skip()...
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!!