updated invalid regex pattern handling

This commit is contained in:
Virendra Patil 2024-06-27 00:35:26 +05:30
parent 7501995f6c
commit 3089c17b5b
1 changed files with 7 additions and 4 deletions

View File

@ -1007,9 +1007,12 @@ class RaisesContext(ContextManager[_pytest._code.ExceptionInfo[E]]):
# Cast to narrow the exception type now that it's verified.
exc_info = cast(Tuple[Type[E], E, TracebackType], (exc_type, exc_val, exc_tb))
self.excinfo.fill_unfilled(exc_info)
try:
if self.match_expr is not None:
if self.match_expr is not None:
re_error = None
try:
self.excinfo.match(self.match_expr)
except re.error as e:
fail(f"Invalid regex pattern provided to 'match': {e}")
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