From de96d738ebfd206810e2e216bd571895fa2ac0f6 Mon Sep 17 00:00:00 2001 From: Allan Olweny Date: Sat, 18 May 2024 14:28:36 -0400 Subject: [PATCH] Add warning for an empty group in the message string --- src/_pytest/config/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index c698ea9a777..1bae77c87c6 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1924,6 +1924,13 @@ def parse_warning_filter( raise UsageError(error_template.format(error=exception_text)) from None if message and escape: message = re.escape(message) + if "()" in message: + warning = dedent( + """ + An empty group '()' will not match a string that contains literal parenthesis + """ + ) + warnings.warn(PytestConfigWarning(warning)) if module and escape: module = re.escape(module) + r"\Z" if lineno_: