--- contrib/python/PyHamcrest/py3/hamcrest/core/core/raises.py (index) +++ contrib/python/PyHamcrest/py3/hamcrest/core/core/raises.py (working tree) @@ -18,12 +18,14 @@ class Raises(BaseMatcher[Callable[..., Any]]): expected: Type[Exception], pattern: Optional[str] = None, matching: Optional[Matcher] = None, + matcher: Optional[Matcher] = None, ) -> None: self.pattern = pattern - self.matcher = matching + self.matcher = matching or matcher self.expected = expected self.actual: Optional[BaseException] = None self.function: Optional[Callable[..., Any]] = None + self.actual_return_value = None def _matches(self, function: Callable[..., Any]) -> bool: if not callable(function): @@ -35,7 +37,7 @@ class Raises(BaseMatcher[Callable[..., Any]]): def _call_function(self, function: Callable[..., Any]) -> bool: self.actual = None try: - function() + self.actual_return_value = function() except BaseException: self.actual = sys.exc_info()[1] @@ -51,6 +53,9 @@ class Raises(BaseMatcher[Callable[..., Any]]): def describe_to(self, description: Description) -> None: description.append_text("Expected a callable raising %s" % self.expected) + if self.matcher is not None: + description.append_text("\n and ") + description.append_description_of(self.matcher) def describe_mismatch(self, item, description: Description) -> None: if not callable(item): @@ -64,7 +69,7 @@ class Raises(BaseMatcher[Callable[..., Any]]): return if self.actual is None: - description.append_text("No exception raised.") + description.append_text("No exception raised and actual return value = '{}'".format(self.actual_return_value)) elif isinstance(self.actual, self.expected): if self.pattern is not None or self.matcher is not None: description.append_text("Correct assertion type raised, but ") @@ -88,7 +93,7 @@ class Raises(BaseMatcher[Callable[..., Any]]): ) -def raises(exception: Type[Exception], pattern=None, matching=None) -> Matcher[Callable[..., Any]]: +def raises(exception: Type[Exception], pattern=None, matching=None, matcher=None) -> Matcher[Callable[..., Any]]: """Matches if the called function raised the expected exception. :param exception: The class of the expected exception @@ -109,7 +114,7 @@ def raises(exception: Type[Exception], pattern=None, matching=None) -> Matcher[C raises(HTTPError, matching=has_properties(status_code=500) ) """ - return Raises(exception, pattern, matching) + return Raises(exception, pattern, matching, matcher) class DeferredCallable(object):