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 <>
The Python reference says:


exception AssertionError
Raised when an assert statement fails.


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

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.
Date User Action Args
2022-03-10 09:44:46tfish2setrecipients: + tfish2
2022-03-10 09:44:46tfish2setmessageid: <>
2022-03-10 09:44:46tfish2linkissue46972 messages
2022-03-10 09:44:46tfish2create