From ba4ef88e0176ee1e6a6aa161cacd69215be2cdeb Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Fri, 4 Jun 2021 11:25:33 +0200 Subject: [PATCH] Allow to specify an exception as cause in skipping reason details Change-Id: If5b7e4306a4bfcd877619a9f747a8db2cd98d36e --- tobiko/common/_skip.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tobiko/common/_skip.py b/tobiko/common/_skip.py index c893809b1..976454138 100644 --- a/tobiko/common/_skip.py +++ b/tobiko/common/_skip.py @@ -15,13 +15,14 @@ from __future__ import absolute_import import functools import inspect -import typing # noqa +import typing import fixtures import testtools -SkipException = testtools.TestCase.skipException # type: typing.Type +SkipException: typing.Type[Exception] = ( + testtools.TestCase.skipException) SkipTarget = typing.Union[typing.Callable, typing.Type[testtools.TestCase], @@ -29,9 +30,11 @@ SkipTarget = typing.Union[typing.Callable, SkipDecorator = typing.Callable[[SkipTarget], SkipTarget] -def skip_test(reason: str): +def skip_test(reason: str, cause: Exception = None) -> typing.NoReturn: """Interrupt test case execution marking it as skipped for given reason""" - raise SkipException(reason) + if cause is not None: + reason += f"\n\n{cause}" + raise SkipException(reason) from cause def skip(reason: str) -> SkipDecorator: