Skip to content

Add warning for an empty group in the message string #12338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,13 @@
raise UsageError(error_template.format(error=exception_text)) from None
if message and escape:
message = re.escape(message)
if "()" in message:
warning = dedent(

Check warning on line 1928 in src/_pytest/config/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/config/__init__.py#L1928

Added line #L1928 was not covered by tests
"""
An empty group '()' will not match a string that contains literal parenthesis
"""
)
warnings.warn(PytestConfigWarning(warning))

Check warning on line 1933 in src/_pytest/config/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/config/__init__.py#L1933

Added line #L1933 was not covered by tests
if module and escape:
module = re.escape(module) + r"\Z"
if lineno_:
Expand Down
Loading