Improvement: extend pytest.raises to support Exception having __repr__ method and initialized with kwargs parameter, except default repr.
This commit is contained in:
parent
22cfac7b9f
commit
2e72b40739
|
@ -709,7 +709,10 @@ class ExceptionInfo(Generic[E]):
|
|||
__tracebackhide__ = True
|
||||
value = str(self.value)
|
||||
if not value:
|
||||
value = repr(self.value)
|
||||
repr_value = repr(self.value)
|
||||
default_repr = f"{self.type.__name__}()"
|
||||
if repr_value != default_repr:
|
||||
value = repr_value
|
||||
msg = f"Regex pattern did not match.\n Regex: {regexp!r}\n Input: {value!r}"
|
||||
if regexp == value:
|
||||
msg += "\n Did you mean to `re.escape()` the regex?"
|
||||
|
|
|
@ -173,7 +173,7 @@ class TestRaises:
|
|||
if method == "function":
|
||||
pytest.raises(ValueError, t)
|
||||
elif method == "function_match":
|
||||
pytest.raises(ValueError, t).match(r"ValueError\(\)")
|
||||
pytest.raises(ValueError, t).match("^$")
|
||||
else:
|
||||
with pytest.raises(ValueError):
|
||||
t()
|
||||
|
|
Loading…
Reference in New Issue