How to use iter_all_after method in Slash

Best Python code snippet using slash

test_interruptions.py

Source:test_interruptions.py Github

copy

Full Screen

...38 assert cleanup not in summary.events39def test_sigterm_interrupt(suite, suite_test):40 suite_test.append_line('raise slash.exceptions.TerminatedException()')41 suite_test.expect_interruption()42 for test in suite.iter_all_after(suite_test):43 test.expect_deselect()44 suite.run(expect_interruption=True)45@pytest.mark.parametrize('hook_name', ['session_start', 'test_start'])46def test_sigterm_on_hook(suite, hook_name):47 @gossip.register('slash.{}'.format(hook_name))48 def session_start(): # pylint: disable=unused-variable49 raise slash.exceptions.TerminatedException('Terminated by signal')50 assert suite51 for index, test in enumerate(suite):52 if index == 0 and hook_name == 'test_start':53 # first test should be interrupted...54 test.expect_interruption()55 else:56 test.expect_deselect()57 result = suite.run(expect_interruption=True)58def test_test_end_called_for_interrupted_test(interrupted_suite, interrupted_test):59 ended = []60 @gossip.register('slash.test_end')61 def test_end():62 ended.append(slash.context.test.__slash__.id)63 s = interrupted_suite.run(expect_interruption=True)64 result = s[interrupted_test]65 assert result.test_metadata.id in ended66def test_ayalas(interrupted_suite, interrupted_test, interrupted_index, config_override, tmpdir):67 config_override('log.format', 'file: {record.message}')68 config_override('log.console_format', 'console: {record.message}')69 config_override('log.root', str(tmpdir))70 callback = Checkpoint()71 slash.hooks.log_file_closed.register(callback) # pylint: disable=no-member72 result = interrupted_suite.run(expect_interruption=True)73 num_closed_log_files = interrupted_index + 2 # One for each test that run (the index is zero based) + session log74 assert callback.called_count == num_closed_log_files75def test_session_interruption_in_start(suite, suite_test, session_interrupt):76 @suite.slashconf.append_body77 def __code__():78 @slash.hooks.session_start.register # pylint: disable=no-member79 def session_cleanup():80 raise KeyboardInterrupt()81 for test in suite:82 test.expect_deselect()83 suite.run(expect_interruption=True)84 assert session_interrupt.called_count == 185def test_interrupt_hooks_should_be_called_once(suite, suite_test, is_last_test, session_interrupt, test_interrupt_callback):86 @suite_test.append_body87 def __code__():88 @slash.add_critical_cleanup89 def cleanup():90 raise KeyboardInterrupt('A')91 raise KeyboardInterrupt('B')92 suite_test.expect_interruption()93 for t in suite.iter_all_after(suite_test, assert_has_more=not is_last_test):94 t.expect_deselect()95 result = suite.run(expect_interruption=True)96 assert test_interrupt_callback.called_count == 197 assert session_interrupt.called_count == 198 assert result.session.results.global_result.is_interrupted()99def test_interrupted_with_custom_exception(suite, suite_test, request):100 import test101 class CustomException(Exception):102 pass103 test.__interruption_exception__ = CustomException104 prev_interruption_exceptions = slash.exceptions.INTERRUPTION_EXCEPTIONS105 slash.exceptions.INTERRUPTION_EXCEPTIONS += (CustomException,)106 @request.addfinalizer107 def cleanup():108 del test.__interruption_exception__109 slash.exceptions.INTERRUPTION_EXCEPTIONS = prev_interruption_exceptions110 suite_test.append_line('import test')111 suite_test.append_line('raise test.__interruption_exception__()')112 suite_test.expect_interruption()113 for t in suite.iter_all_after(suite_test):114 t.expect_deselect()115 results = suite.run(expect_interruption=True)116def test_test_interrupt_hook_exception(suite_builder):117 # pylint: disable=reimported,redefined-outer-name118 @suite_builder.first_file.add_code119 def __code__():120 import slash121 @slash.hooks.test_interrupt.register # pylint: disable=no-member122 def test_interrupt(**_):123 1/0 # pylint: disable=pointless-statement124 def test_1():125 raise KeyboardInterrupt()126 def test_2():127 pass...

Full Screen

Full Screen

test_running.py

Source:test_running.py Github

copy

Full Screen

...9 suite_test = suite[2]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):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']...

Full Screen

Full Screen

test_add_error.py

Source:test_add_error.py Github

copy

Full Screen

...55 @suite_test.append_body56 def __code__(): # pylint: disable=unused-variable57 slash.add_error('bla').mark_fatal() # pylint: disable=undefined-variable58 suite_test.expect_error()59 for test in suite.iter_all_after(suite_test):60 test.expect_not_run()61 session = suite.run().session62 assert session.results.has_fatal_errors()63def test_session_level_add_error_message(suite, suite_test):64 @suite_test.file.append_body65 def __code__(): # pylint: disable=unused-variable66 @slash.hooks.session_end.register # pylint: disable=undefined-variable67 def _callback():68 slash.add_error('session: add_error') # pylint: disable=undefined-variable69 res = suite.run(expect_session_errors=True)70 errors = res.session.results.global_result.get_errors()71 assert len(errors) == 172 [err] = errors73 assert err.message == 'session: add_error'...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful