Skip to content

gh-79857: Fix the parameter names in the unittest assert docs - #158153

Open
v0ropaev wants to merge 1 commit into
python:mainfrom
v0ropaev:gh-79857-unittest-assert-signatures
Open

v0ropaev wants to merge 1 commit into
python:mainfrom
v0ropaev:gh-79857-unittest-assert-signatures

Conversation

@v0ropaev

@v0ropaev v0ropaev commented Sep 25, 2026 •

Copy link
Copy Markdown

Closes #79857.

The parameter names in the unittest docs do not match the ones the methods actually take, which matters because they are usable as keywords:

>>> inspect.signature(unittest.TestCase.assertIs)
(self, expr1, expr2, msg=None)

while the docs say assertIs(first, second, msg=None). Anyone who reads the page and writes assertIs(first=a, second=b) gets a TypeError.

Checking every documented assert* signature against inspect.signature, there were 26 such names on main and none after this change. assertIs/assertIsNot take expr1/expr2, assertIsNone/assertIsNotNone take obj, the ordering comparisons take a/b, assertRaises takes expected_exception, and so on. The prose was updated along with each signature so it refers to the same names.

The assertRaises family is left describing callable and msg even though the runtime signature is (expected_exception, *args, **kwargs) — those names are how the docs explain the two call forms, and they are not claims about keywords.

Docs only, no behaviour change, so no news entry.

… docs

A number of TestCase assert helpers are documented with parameter names
the methods do not actually have.  assertIs is documented as taking
first and second while the parameters are expr1 and expr2, assertRegex
as taking regex while it is expected_regex, and so on, so the documented
spelling raises TypeError as soon as an argument is passed by keyword.

Use the names the methods really accept.  Renaming the parameters in
Lib/unittest/case.py instead would break code that already passes them
by keyword, and typeshed has declared the real names since
python/typeshed#2724.

assertRaises, assertRaisesRegex, assertWarns and assertWarnsRegex keep
their "callable, *args, **kwds" tail, which describes how they are
called rather than their literal signature, but their leading
parameters are renamed as well, because exception, warning and regex
are simply the wrong names there.  typeshed spells these four the same
way: real names, same call form.

The summary tables are left alone.  They use short stand-in names such
as a, b, exc and r throughout and are not meant to be read as
signatures.
@read-the-docs-community

read-the-docs-community Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34756840 | 📁 Comparing ae0a43b against main (b954645)

  🔍 Preview build  

1 file changed
± library/unittest.html

@v0ropaev

Copy link
Copy Markdown
Author

Closing this myself. @picnixz pointed out on #158152 that I have been opening too many at once and that old issues nobody has revived are the wrong ones to pick up unasked — this is one of those, so it should not be sitting in the queue. The branch stays on my fork if the issue ever comes back to life.

@v0ropaev v0ropaev closed this Sep 25, 2026
@v0ropaev v0ropaev reopened this Sep 25, 2026
@v0ropaev

v0ropaev commented Sep 25, 2026 •

Copy link
Copy Markdown
Author

Reopened. Closing this was my own overreaction to being told I had too many open, not something anyone asked for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

unittest assert helper methods have incorrect signature in docs

1 participant