FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-134567: Exposes log format to users in unittest.TestCase.assertLogs by garry-cairns · Pull Request #134570 · python/cpython · GitHub

Repository navigation

gh-134567: Exposes log format to users in unittest.TestCase.assertLogs - #134570

Merged
serhiy-storchaka merged 12 commits into
python:mainfrom
garry-cairns:fix-issue-134567
Jul 2, 2025
Merged

serhiy-storchaka merged 12 commits into
python:mainfrom
garry-cairns:fix-issue-134567

Conversation

garry-cairns commented May 23, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Allows users optionally to pass a custom log formatter to assertLogs such that assertions match expected custom formats where they are used. Existing behavior should be unaffected.

python-cla-bot Bot commented May 23, 2025 •
edited
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

bedevere-app Bot commented May 23, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Copy Markdown
Contributor Author

@ezio-melotti @rbtcollins @gpshead @serhiy-storchaka Does anyone have any bandwidth to look a this one? I believe it will be a fairly quick either accept or reject type change.

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

As a new feature, it needs a documentation. Add a versionchanged directive for assertLogs(), add an entry in the What's New document.

I have no strong opinion about this feature.

Comment thread Lib/unittest/case.py Outdated
serhiy-storchaka requested a review from pitrou June 23, 2025 20:03
Comment thread Doc/whatsnew/3.15.rst Outdated
Comment thread Doc/library/unittest.rst Outdated
Comment thread Doc/library/unittest.rst Outdated

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

"so your assertions can match a custom format" looks misleading. It can be misinterpreted as if assertLogs() itself checks that logging messages were formatted using the specified formatter. This is not true. assertLogs() does not check what formatter was used for the specified logger. It uses the specified formatter (or the default one) to format logging messages in output.

I suggest simply saying that a formatter is used to format the strings in output.

Comment thread Doc/library/unittest.rst Outdated
Comment thread Doc/library/unittest.rst Outdated

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please update also What's New and the versionchanged directive.

Copy link
Copy Markdown
Contributor Author

Please update also What's New and the versionchanged directive.

Can you clarify what's outstanding here? I thought I had addressed these with the previous commit.

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

They still contain "so your assertions can match". You only changed the NEWS entry.

Copy link
Copy Markdown
Contributor Author

They still contain "so your assertions can match". You only changed the NEWS entry.

Ah got you, should be sorted now. Thanks for all your help and attention on this.

serhiy-storchaka commented Jul 2, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

LGTM. 👍

serhiy-storchaka enabled auto-merge (squash) July 2, 2025 09:40
serhiy-storchaka merged commit 51ab66b into python:main Jul 2, 2025
garry-cairns deleted the fix-issue-134567 branch July 2, 2025 13:01
Comment thread Doc/whatsnew/3.15.rst
Comment on lines +294 to +300
unittest
--------

* Lets users specify formatter in TestCase.assertLogs.
:func:`unittest.TestCase.assertLogs` will now accept a formatter
to control how messages are formatted.
(Contributed by Garry Cairns in :gh:`134567`.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@garry-cairns This is under the "Removed" section:

https://docs.python.org/3.15/whatsnew/3.15.html#removed

Please could you move it to the "Improved modules" section above?

https://docs.python.org/3.15/whatsnew/3.15.html#improved-modules

(We could also remove the first sentence "Lets users specify formatter in TestCase.assertLogs", as the next sentence essentially repeats it.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Apologies for the noise on this. I've created #136630 to resolve this.

AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
picnixz pushed a commit to picnixz/cpython that referenced this pull request Jul 13, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL