Skip to content

Fix test_import assertions that never compared against the expected value - #161831

Open
andresdelfino wants to merge 1 commit into
python:mainfrom
andresdelfino:fix-test-import-assertisnotnone
Open

andresdelfino wants to merge 1 commit into
python:mainfrom
andresdelfino:fix-test-import-assertisnotnone

Conversation

@andresdelfino

Copy link
Copy Markdown
Contributor

test_pyinit_function_raises_exception passed the expected value as the second argument of assertIsNotNone(), which is the failure message:

self.assertIsNotNone(exception.type.__name__, "ImportError")
self.assertIsNotNone(exception.msg, "failed to import from subinterpreter due to exception")

So the test only checked that the type name and message were not None, and never compared them with the intended values. This switches both to assertEqual(). The expected message matches the ImportError raised in Python/import.c (added in gh-144601).

Follow-up to #161774, which fixed the same mistake with assertTrue(). It was found the same way, by walking the AST of every tracked .py file for assert* calls whose msg argument isn't a string, then reviewing each hit by hand. The other hits either pass useful context (inputs, process output, etc.) or are harmless leftovers such as assertIsNone(x, None), so they are left alone.

Test-only change, so this should be fine for skip issue / skip news. Tested locally on Linux.

🤖 Generated with Claude Code

…alue

test_pyinit_function_raises_exception called assertIsNotNone() with the
expected value as the second argument, which is the failure message, so
the exception's type name and message were never checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant