handled invalid regex pattern exception inside init
This commit is contained in:
parent
24ec45d881
commit
6e91c332ba
|
@ -987,6 +987,14 @@ class RaisesContext(ContextManager[_pytest._code.ExceptionInfo[E]]):
|
||||||
self.message = message
|
self.message = message
|
||||||
self.match_expr = match_expr
|
self.match_expr = match_expr
|
||||||
self.excinfo: _pytest._code.ExceptionInfo[E] | None = None
|
self.excinfo: _pytest._code.ExceptionInfo[E] | None = None
|
||||||
|
if self.match_expr is not None:
|
||||||
|
re_error = None
|
||||||
|
try:
|
||||||
|
re.compile(self.match_expr)
|
||||||
|
except re.error as e:
|
||||||
|
re_error = e
|
||||||
|
if re_error is not None:
|
||||||
|
fail(f"Invalid regex pattern provided to 'match': {re_error}")
|
||||||
|
|
||||||
def __enter__(self) -> _pytest._code.ExceptionInfo[E]:
|
def __enter__(self) -> _pytest._code.ExceptionInfo[E]:
|
||||||
self.excinfo = _pytest._code.ExceptionInfo.for_later()
|
self.excinfo = _pytest._code.ExceptionInfo.for_later()
|
||||||
|
@ -1008,11 +1016,5 @@ class RaisesContext(ContextManager[_pytest._code.ExceptionInfo[E]]):
|
||||||
exc_info = cast(Tuple[Type[E], E, TracebackType], (exc_type, exc_val, exc_tb))
|
exc_info = cast(Tuple[Type[E], E, TracebackType], (exc_type, exc_val, exc_tb))
|
||||||
self.excinfo.fill_unfilled(exc_info)
|
self.excinfo.fill_unfilled(exc_info)
|
||||||
if self.match_expr is not None:
|
if self.match_expr is not None:
|
||||||
re_error = None
|
self.excinfo.match(self.match_expr)
|
||||||
try:
|
|
||||||
self.excinfo.match(self.match_expr)
|
|
||||||
except re.error as e:
|
|
||||||
re_error = e
|
|
||||||
if re_error is not None:
|
|
||||||
fail(f"Invalid regex pattern provided to 'match': {re_error}")
|
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue