gh-134567: Exposes log format to users in unittest.TestCase.assertLogs#134570
gh-134567: Exposes log format to users in unittest.TestCase.assertLogs#134570serhiy-storchaka merged 12 commits intopython:mainfrom
Conversation
|
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 |
|
@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
There was a problem hiding this comment.
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.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
"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.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
|
LGTM. 👍 |
| 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`.) |
There was a problem hiding this comment.
@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.)
There was a problem hiding this comment.
Apologies for the noise on this. I've created #136630 to resolve this.
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.