Skip to content

recwarn: improved warns(match=...) error message on regex mismatch (closes #11225)#14310

Open
JaeHyuckSa wants to merge 3 commits intopytest-dev:mainfrom
JaeHyuckSa:issue-11225
Open

recwarn: improved warns(match=...) error message on regex mismatch (closes #11225)#14310
JaeHyuckSa wants to merge 3 commits intopytest-dev:mainfrom
JaeHyuckSa:issue-11225

Conversation

@JaeHyuckSa
Copy link

When using pytest.warns(match=...), even if a warning of the expected type was emitted, the first sentence of the error message said "DID NOT WARN" when the regex did not match. Since this made it seem as though no warning had been emitted at all, I updated it to make the situation clearer.

  • The updated result can be seen below!

Before:

Failed: DID NOT WARN. No warnings of type (<class 'FutureWarning'>,) matching the regex were emitted.
 Regex: `Blablabla` is deprecated (more info)
 Emitted warnings: [FutureWarning('`Blablabla` is deprecated (more info)')]

After:

Failed: Regex pattern did not match.
 Regex: '`Blablabla` is deprecated (more info)'
 Emitted warnings: [FutureWarning('`Blablabla` is deprecated (more info)')].
 Did you mean to `re.escape()` the regex?

Closes #11225


  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Add text like closes #XYZW to the PR description and/or commits.
  • If AI agents were used, they are credited in Co-authored-by commit trailers.
  • Create a new changelog file in the changelog directory.
  • Add yourself to AUTHORS in alphabetical order.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Mar 22, 2026
@JaeHyuckSa JaeHyuckSa changed the title recwarn: improved warns(match=...) error message on regex mismatch (closes #11225) recwarn: improved warns(match=...) error message on regex mismatch (closes #11225) Mar 22, 2026
@JaeHyuckSa JaeHyuckSa force-pushed the issue-11225 branch 2 times, most recently from 293241c to b4e2d97 Compare March 22, 2026 17:29
…loses pytest-dev#11225)

Signed-off-by: JaeHyuckSa <jaehyuck.sa.dev@gmail.com>
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.

Error message for pytest.warns() if regex patterns don't match

1 participant