Best Python code snippet using slash
test_slash_resume.py
Source:test_slash_resume.py
...19 fail_index = len(suite) // 220 suite[fail_index].when_run.fail()21 for index, test in enumerate(suite):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()104 else:105 suite_test.when_run.fail()106 result = suite.run()107 if failed_first:108 config_override('resume.failed_first', True)109 else:110 config_override('resume.unstarted_first', True)111 [resumed_test] = get_tests_from_previous_session(result.session.id)112 assert resumed_test.address_in_file == address_in_file(suite_test)113@pytest.mark.parametrize('failed_only', [True, False])114def test_failed_only_or_unstarted_first(suite, failed_only, config_override):115 fail_index = len(suite) // 2116 skip_index = fail_index - 1117 suite[skip_index].when_run.skip()118 suite[fail_index].when_run.fail()119 for index, test in enumerate(suite):120 if index > fail_index:121 test.expect_not_run()122 result = suite.run(additional_args=['-x'])123 if failed_only:124 config_override('resume.failed_only', True)125 expected_resume_tests_num = 1126 expected_status = 'failed'127 else:128 config_override('resume.unstarted_only', True)129 expected_resume_tests_num = len(suite) - fail_index130 expected_status = 'planned'131 resumed = get_tests_from_previous_session(result.session.id)132 assert len(resumed) == expected_resume_tests_num133 for test in resumed:134 assert test.status == expected_status135def test_resuming_interrupted_session(suite):...
test_running.py
Source:test_running.py
...10 suite_test.append_line('slash.{}("err")'.format(adder))11 suite_test.append_line('slash.skip_test()')12 suite_test.expect_skip()13 for test in suite.iter_all_after(suite_test, assert_has_more=True):14 test.expect_not_run()15 summary = suite.run(additional_args=['-x'])16 [result] = summary.get_all_results_for_test(suite_test)17 assert result.has_skips()18 assert result.has_errors_or_failures()19@pytest.mark.parametrize('adder', ['add_failure', 'add_error'])20def test_stop_on_error_from_previous_run(suite, adder):21 test_a = suite[2]22 test_b = suite[4]23 # avoid slash.ctx here, because the stored object would be a proxy24 test_a.append_line('slash.g.inject_to_result = slash.context.session.results.current')25 test_b.append_line('slash.g.inject_to_result.{}("injected")'.format(adder))26 if adder == 'add_error':27 test_a.expect_error()28 elif adder == 'add_failure':29 test_a.expect_failure()30 else:31 raise NotImplementedError() # pragma: no cover32 all_after = list(suite.iter_all_after(test_b))33 assert all_after34 for test in all_after:35 test.expect_not_run()36 suite.run(additional_args=['-x'])37def test_run_tests_fails_without_active_session():38 with pytest.raises(NoActiveSession):39 run_tests([])40def test_simple_run(suite):41 suite.run()42def test_iter_results_ordering(suite):43 for index, test in enumerate(suite):44 test.append_line('slash.context.result.data["index"] = {}'.format(index))45 results = list(suite.run().session.results.iter_test_results())46 for index, result in enumerate(results):47 assert result.data['index'] == index48def test_failed(suite, suite_test):49 suite_test.when_run.fail()50 result = suite.run()[suite_test]51 assert result.is_failure()52 assert not result.is_error()53 assert not result.is_success()54def test_error(suite, suite_test):55 suite_test.when_run.error()56 result = suite.run()[suite_test]57 assert result.is_error()58 assert not result.is_failure()59 assert not result.is_success()60def test_skip(suite, suite_test):61 suite_test.when_run.skip()62 result = suite.run()[suite_test]63 assert result.is_skip()64 assert not result.is_error()65 assert not result.is_failure()66 assert not result.is_success()67def test_stop_on_fatal_exception(suite, suite_test, fatal_error_adder):68 fatal_error_adder(suite_test)69 for remaining_test in suite.iter_all_after(suite_test):70 remaining_test.expect_not_run()71 suite.run()72@pytest.mark.parametrize('stop_through_config', [True, False])73def test_stop_on_error(suite, suite_test, failure_type, stop_through_config, config_override):74 if failure_type == 'error':75 suite_test.when_run.error()76 elif failure_type == 'failure':77 suite_test.when_run.fail()78 else:79 raise NotImplementedError() # pragma: no cover80 for test in suite.iter_all_after(suite_test):81 test.expect_not_run()82 if stop_through_config:83 config_override('run.stop_on_error', True)84 kwargs = {}85 else:86 config_override('run.stop_on_error', False)87 kwargs = {'additional_args': ['-x']}88 suite.run(**kwargs)89def test_stop_on_error_unaffected_by_skips(suite, suite_test):90 suite_test.when_run.skip()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):...
test.py
Source:test.py
...36 def expect_interruption(self):37 self._expect(_INTERRUPT)38 def expect_skip(self):39 self._expect(_SKIP)40 def expect_not_run(self):41 self._expect(_NOT_RUN)42 def expect_deselect(self):43 self._selected = False44 def is_selected(self):45 return self._selected46 def _expect(self, expected_result):47 if self._expected_result != _SUCCESS:48 raise NotImplementedError() # pragma: no cover49 self._expected_result = expected_result50 def get_expected_result(self):51 return self._expected_result52 def is_method_test(self):53 raise NotImplementedError() # pragma: no cover54 def is_function_test(self):...
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!!