Visitar URL original
Warn on impossible-to-match message pattern in filterwarnings by giovanamalaia · Pull Request #15364 · pytest-dev/pytest · GitHub
Skip to content

Warn on impossible-to-match message pattern in filterwarnings - #15364

Open
giovanamalaia wants to merge 1 commit into
pytest-dev:mainfrom
giovanamalaia:issue-10478-warn-filterwarnings
Open

giovanamalaia wants to merge 1 commit into
pytest-dev:mainfrom
giovanamalaia:issue-10478-warn-filterwarnings

Conversation

@giovanamalaia

Copy link
Copy Markdown

Summary

This PR addresses issue #10478 by warning users when they configure a filterwarnings message containing an unescaped empty regex group (). Users often write () expecting it to match literal parentheses (e.g., ignore:The foo.bar() function is deprecated), but since the message is interpreted as a regular expression, it behaves as an empty group and silently fails to match the literal text.

What I changed

  • Lightweight Scanner: Added a private scanner function _has_empty_regex_group in src/_pytest/config/__init__.py to safely detect unescaped () outside of character classes.
  • Warning Emission: Added _warn_on_empty_regex_group to emit a PytestConfigWarning when escape=False, guiding the user to escape the parentheses (\(\)) or use re.escape().
  • Testing: Added a test suite (TestEmptyGroupInFilterMessage) in testing/test_warnings.py validating true positives (e.g., ()) and true negatives (e.g., [()], \(\), foo(bar), foo(a|)).
  • Changelog & Authors: Included the changelog file (changelog/10478.improvement.rst) and updated AUTHORS.

AI Assistance

  • GitHub Copilot was used as an interactive tool to assist in drafting the regex scanner logic and parameterizing edge-case tests. All changes were rigorously reviewed, tested locally, and validated by the author.

Closes #10478

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn on impossible-to-match message pattern in filterwarnings - likely user error

1 participant