This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tfish2
Recipients tfish2
Date 2022-03-10.09:44:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1646905486.67.0.783441302019.issue46972@roundup.psfhosted.org>
In-reply-to
Content
The Python reference says:

(1) https://docs.python.org/3/library/exceptions.html#concrete-exceptions

exception AssertionError
Raised when an assert statement fails.

(2) https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement

"assert ..." is equivalent to "if __debug__: ..."

From this, one can infer the guarantee "the -O flag will suppress AssertionError exceptions from being raised".

However, there is code in the Python standard library that does a direct "raise AssertionError" (strictly speaking, in violation of (1)), and it is just reasonable to assume that other code following the design of that would then also want to do a direct "raise AssertionError".

This happens e.g. in many methods defined in: unittest/mock.py

The most appropriate fix here may be to change the documentation to not say:

===
exception AssertionError
Raised when an assert statement fails.
===

but instead:

===
exception AssertionError
An assert[{add reference to `assert` definition}] statement fails, or a unit testing related assert{...}() callable detects an assertion violation.
===
History
Date User Action Args
2022-03-10 09:44:46tfish2setrecipients: + tfish2
2022-03-10 09:44:46tfish2setmessageid: <1646905486.67.0.783441302019.issue46972@roundup.psfhosted.org>
2022-03-10 09:44:46tfish2linkissue46972 messages
2022-03-10 09:44:46tfish2create