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 — Fix test assertions that never compared against the expected value by andresdelfino · Pull Request #161774 · python/cpython

Conversation

@andresdelfino

@andresdelfino andresdelfino commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

assertTrue(first, second) treats second as the failure message, so each of these assertions only checked that first was truthy and never compared it with the intended value. This switches them to assertEqual() or assertIs().

They were found by walking the AST of every tracked .py file for assertTrue/assertFalse calls with two positional arguments and reviewing each hit by hand; the remaining ones pass a genuine failure message.

Two of the corrected assertions would have failed as-is, because the expected value had gone stale:

  • test_ssl.test_ecc_cert: TLS 1.3 is negotiated here, and TLS 1.3 cipher suite names (e.g. TLS_AES_256_GCM_SHA384) don't include the key exchange or authentication algorithm, so the ECDHE-ECDSA prefix check only makes sense for TLS 1.2. It is now done only when TLS 1.2 is negotiated. test_dual_rsa_ecc pins TLS 1.2 and keeps the unconditional check. Dropping the check from test_ecc_cert instead would also be reasonable.
  • test_ttk_textonly.test_format_elemcreate: _format_elemcreate(None) has returned ((),) rather than (None, ()) since ttk.Style.element_create using incorrect tk.call syntax #68166 changed the function's return format; the expected value is updated to match.

In the ctypes tests the expected values were str while the functions return bytes, so they are now bytes literals.

Test-only change, so this should be fine for skip issue / skip news. Tested locally on Linux with OpenSSL 3.0.13; test_ttk_textonly was not run locally (no _tkinter).

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

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

All reactions
@andresdelfino @claude
Fix assertTrue() calls that pass the expected value as msg
1c814e2
assertTrue(first, second) treats the second argument as the failure
message, so these assertions only checked that the first argument was
truthy.  Use assertEqual() or assertIs() so the expected value is
actually compared.

Two of them were hiding stale expectations:

* test_ssl.test_ecc_cert: since TLS 1.3 is negotiated, the cipher suite
  name no longer starts with "ECDHE-ECDSA".  Only check it for TLS 1.2.
* test_ttk_textonly.test_format_elemcreate: _format_elemcreate(None)
  returns ((),) since pythongh-68166 changed its return format.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@andresdelfino
andresdelfino requested review from barneygale, ethanfurman, gpshead and picnixz as code owners November 10, 2026 18:30
@bedevere-app bedevere-app Bot added tests Tests in the Lib/test dir awaiting review labels Nov 10, 2026
ethanfurman
ethanfurman approved these changes Nov 10, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Nov 10, 2026
StanFromIreland
StanFromIreland reviewed Nov 11, 2026
View reviewed changes
Comment thread Lib/test/test_ssl.py Outdated
self.assertTrue(cert, "Can't get peer certificate.")
cipher = s.cipher()[0].split('-')
self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA'))
# TLS 1.3 cipher suite names don't include the key exchange

@StanFromIreland StanFromIreland Nov 11, 2026

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.

This now duplicates test_dual_rsa_ecc below, let's drop this.

Sorry, something went wrong.

Uh oh!

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

All reactions
@StanFromIreland StanFromIreland added skip issue skip news labels Nov 11, 2026
StanFromIreland
StanFromIreland reviewed Nov 11, 2026
View reviewed changes
Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

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

@StanFromIreland
Apply suggestion from @StanFromIreland
5313c9d
@StanFromIreland StanFromIreland changed the title Fix assertTrue() calls that pass the expected value as msg Fix test assertions that never compared against the expected value Nov 11, 2026
StanFromIreland
StanFromIreland approved these changes Nov 11, 2026
View reviewed changes
@StanFromIreland
StanFromIreland enabled auto-merge (squash) November 11, 2026 18:16
@StanFromIreland
StanFromIreland merged commit aecef70 into python:main Nov 11, 2026
50 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 11, 2026
@andresdelfino
andresdelfino deleted the fix-asserttrue-misuse branch November 11, 2026 19:08
@StanFromIreland StanFromIreland added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 11, 2026
@miss-islington-app

miss-islington-app Bot commented Nov 11, 2026

Copy link
Copy Markdown

Thanks @andresdelfino for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@miss-islington-app

miss-islington-app Bot commented Nov 11, 2026

Copy link
Copy Markdown

Thanks @andresdelfino for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app

bedevere-app Bot commented Nov 11, 2026

Copy link
Copy Markdown

GH-161823 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 11, 2026
@bedevere-app

bedevere-app Bot commented Nov 11, 2026

Copy link
Copy Markdown

GH-161824 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 11, 2026
StanFromIreland added a commit that referenced this pull request Nov 11, 2026
@miss-islington @andresdelfino @StanFromIreland
[3.14] Fix test assertions that never compared against the expected v…
f3b7130
…alue (GH-161774) (#161823)

(cherry picked from commit aecef70)

Co-authored-by: Andrés Delfino <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
StanFromIreland added a commit that referenced this pull request Nov 11, 2026
@miss-islington @andresdelfino @StanFromIreland
[3.15] Fix test assertions that never compared against the expected v…
f2a3355
…alue (GH-161774) (#161824)

(cherry picked from commit aecef70)

Co-authored-by: Andrés Delfino <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
This was referenced Nov 11, 2026
Fix test_import assertions that never compared against the expected value #161831
Open
Fix copy-pasted assert messages in test_crossinterp #161835
Open
orsenthil pushed a commit to orsenthil/cpython that referenced this pull request Nov 12, 2026
@andresdelfino @StanFromIreland @orsenthil
Fix test assertions that never compared against the expected value (p…
e08172d
…ython#161774)

Co-authored-by: Stan Ulbrych <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ethanfurman ethanfurman ethanfurman approved these changes
@StanFromIreland StanFromIreland StanFromIreland approved these changes
@barneygale barneygale Awaiting requested review from barneygale barneygale is a code owner
@gpshead gpshead Awaiting requested review from gpshead gpshead is a code owner
@picnixz picnixz Awaiting requested review from picnixz picnixz is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

skip issue skip news tests Tests in the Lib/test dir

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

@andresdelfino @ethanfurman @StanFromIreland
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.