def test_assert_raises(exc_types, message): raised = CustomException() with slash.Session(): with slash.assert_raises(exc_types, msg=message) as caught: raise raised assert sys.exc_info() == exception_handling.NO_EXC_INFO assert caught.exception is raised
def test_assert_raises_that_not_raises(message): expected_substring = message or 'not raised' try: with slash.assert_raises(Exception, msg=message): pass except TestFailed as e: assert expected_substring in str(e) else: raise Exception('TestFailed exception was not raised :(')
def test_children_not_connected_timeout(runnable_test_dir, config_override): config_override("parallel.worker_connect_timeout", 0) config_override("parallel.num_workers", 1) with Session(): runnables = Loader().get_runnables(str(runnable_test_dir)) parallel_manager = ParallelManager([]) parallel_manager.start_server_in_thread(runnables) time.sleep(0.1) with slash.assert_raises(ParallelTimeout) as caught: parallel_manager.wait_all_workers_to_connect() assert caught.exception.args[0] == 'Not all clients connected'
def test_timeout_no_request_to_server(config_override, runnable_test_dir): config_override("parallel.no_request_timeout", 1) with Session(): runnables = Loader().get_runnables(str(runnable_test_dir)) parallel_manager = ParallelManager([]) parallel_manager.start_server_in_thread(runnables) parallel_manager.server.state = ServerStates.SERVE_TESTS with slash.assert_raises(ParallelTimeout) as caught: parallel_manager.start() assert 'No request sent to server' in caught.exception.args[0]
def test_assert_raises_that_not_raises(message): expected_substring = message or 'not raised' try: with slash.assert_raises(CustomException, msg=message): pass except ExpectedExceptionNotCaught as e: assert expected_substring in str(e) assert e.expected_types == (CustomException, ) else: raise Exception( 'ExpectedExceptionNotCaught exception was not raised :(')
def test_handling_exceptions_inside_assert_raises_with_session(with_session): value = CustomException() with ExitStack() as ctx: if with_session: session = ctx.enter_context(slash.Session()) ctx.enter_context(session.get_started_context()) else: session = None with slash.assert_raises(CustomException): with exception_handling.handling_exceptions(): raise value assert not exception_handling.is_exception_handled(value) if with_session: assert session.results.get_num_errors() == 0
def test_handling_exceptions_inside_assert_raises_with_session(with_session): value = CustomException() with ExitStack() as ctx: if with_session: session = ctx.enter_context(slash.Session()) ctx.enter_context(session.get_started_context()) # https://github.com/PyCQA/pylint/issues/2056: pylint: disable=no-member else: session = None with slash.assert_raises(CustomException): with exception_handling.handling_exceptions(): raise value assert not exception_handling.is_exception_handled(value) if with_session: assert session.results.get_num_errors() == 0
def test_forbid_root_beam(scotty): with slash.assert_raises(HTTPError) as e: scotty.beam_up("/") assert e.exception.response.status_code == http.client.CONFLICT
def test_empty_issue(tracker): with slash.assert_raises(requests.exceptions.HTTPError) as e: tracker.create_issue(' ') assert e.exception.response.status_code == http.client.CONFLICT