def test_passthrough_types(): value = CustomException() with pytest.raises(CustomException) as caught: with exception_handling.handling_exceptions(passthrough_types=(CustomException,)): raise value assert value is caught.value assert not exception_handling.is_exception_handled(value) with pytest.raises(CustomException) as caught: with exception_handling.handling_exceptions(passthrough_types=(AttributeError,)): raise value assert value is caught.value assert exception_handling.is_exception_handled(value)
def test_handling_exceptions_skip_test_would_not_return_skip_test(): with pytest.raises(SkipTest) as caught: with slash.Session(): with exception_handling.handling_exceptions() as handled: raise SkipTest('Unittest') assert isinstance(caught.value, SkipTest) assert handled.exception is caught.value assert exception_handling.is_exception_handled(caught.value)
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_handling_exceptions_inside_allowing_exceptions_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 logbook.TestHandler() as handler: with slash.allowing_exceptions(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 assert len(handler.records) == 0 # pylint: disable=len-as-condition