GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-134567: Exposes log format to users in unittest.TestCase.assertLogs by garry-cairns · Pull Request #134570 · python/cpython

Conversation

@garry-cairns

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

Uh oh!

There was an error while loading. Please reload this page.

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.

  • Issue: Expose log format to users in assertLogs #134567

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@garry-cairns
Exposes log format to users in unittest.TestCase.assertLogs
f8ff127
@python-cla-bot

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

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request May 23, 2025
Expose log format to users in assertLogs #134567
Closed
@bedevere-app bedevere-app Bot added the awaiting review label May 23, 2025
blurb-it Bot and others added 2 commits May 23, 2025 09:19
@blurb-it
📜🤖 Added by blurb_it.
59e8f3f
@garry-cairns
Merge branch 'main' into fix-issue-134567
821f828
@garry-cairns

garry-cairns commented Jun 23, 2025

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed Jun 23, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

garry-cairns reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/unittest/case.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

garry-cairns added 3 commits June 23, 2025 20:24
@garry-cairns
Merge branch 'python:main' into fix-issue-134567
d96dca3
@garry-cairns
Adds docs and corrects docstring
6009858
@garry-cairns
Updates unittest docs
7881c64
@serhiy-storchaka
serhiy-storchaka requested a review from pitrou June 23, 2025 20:03
serhiy-storchaka
serhiy-storchaka reviewed Jun 24, 2025
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/unittest.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/unittest.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

garry-cairns added 2 commits June 25, 2025 14:35
@garry-cairns
Merge branch 'python:main' into fix-issue-134567
ff3e9af
@garry-cairns
Resolves review comments from pr 134570
ec353d2
serhiy-storchaka
serhiy-storchaka reviewed Jun 29, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

"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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/unittest.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/unittest.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

garry-cairns added 2 commits June 29, 2025 14:42
@garry-cairns
Merge branch 'python:main' into fix-issue-134567
766d6a2
@garry-cairns
Addresses review comments on pythongh-134567
7ee8aba
serhiy-storchaka
serhiy-storchaka reviewed Jul 1, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@garry-cairns

garry-cairns commented Jul 1, 2025

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed Jul 2, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
garry-cairns added 2 commits July 2, 2025 10:20
@garry-cairns
Merge branch 'python:main' into fix-issue-134567
10aa529
@garry-cairns
Addresses review comments on pythongh-134570
ca72d91
@garry-cairns

garry-cairns commented Jul 2, 2025

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka approved these changes Jul 2, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jul 2, 2025
@serhiy-storchaka

serhiy-storchaka commented Jul 2, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

LGTM. 👍

garry-cairns reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) July 2, 2025 09:40
@serhiy-storchaka
serhiy-storchaka merged commit 51ab66b into python:main Jul 2, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 2, 2025
@garry-cairns
garry-cairns deleted the fix-issue-134567 branch July 2, 2025 13:01
hugovk
hugovk reviewed Jul 7, 2025
View reviewed changes
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`.)

@hugovk hugovk Jul 7, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@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.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@garry-cairns garry-cairns Jul 13, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
@garry-cairns @AndPuQing
pythongh-134567: Add the formatter parameter in unittest.TestCase.ass…
7dec2ba
…ertLogs (pythonGH-134570)
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
@garry-cairns @Pranjal095
pythongh-134567: Add the formatter parameter in unittest.TestCase.ass…
18a530e
…ertLogs (pythonGH-134570)
picnixz pushed a commit to picnixz/cpython that referenced this pull request Jul 13, 2025
@garry-cairns @picnixz
pythongh-134567: Add the formatter parameter in unittest.TestCase.ass…
10aed12
…ertLogs (pythonGH-134570)
@garry-cairns garry-cairns mentioned this pull request Jul 13, 2025
gh-134567: Move unittest What’s New entry #136630
Merged
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@garry-cairns @taegyunkim
pythongh-134567: Add the formatter parameter in unittest.TestCase.ass…
524a365
…ertLogs (pythonGH-134570)
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
@garry-cairns @Agent-Hellboy
pythongh-134567: Add the formatter parameter in unittest.TestCase.ass…
13fdcbf
…ertLogs (pythonGH-134570)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hugovk hugovk hugovk left review comments
@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@pitrou pitrou Awaiting requested review from pitrou

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@garry-cairns @serhiy-storchaka @hugovk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.