Allow to specify an exception as cause in skipping reason details

Change-Id: If5b7e4306a4bfcd877619a9f747a8db2cd98d36e
This commit is contained in:
Federico Ressi 2021-06-04 11:25:33 +02:00
parent eeacdedee0
commit ba4ef88e01
1 changed files with 7 additions and 4 deletions

View File

@ -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: