Mismatch between assert's semantics and how it's used (-O, -OO, disable)

I will admit to being imprecise with my wording. If a test framework relies on assertions and doesn’t change in the 2-3 year deprecation period, it would stop working. But if I understand this correctly, pytest replaces the assert statements in test files already without checking these flags.

:confused: I thought I was suggesting such a thing. In this scenario the issue isn’t with -O, it’s with the standard runtime mode. Users of -O will see no change in behavior.

If code is using assertions as-documented (used as invariants, should never raise unless there are bad assumptions), nothing should change and no noise will be created. The relevant changes to them are a) testing frameworks that rely on assert need to be aware of this and b) in any other case where they need assert evaluated, they should use python -X dev rather than python [a.k.a. debug], which makes the use case more explicit.

If some code is using them incorrectly (it raises assertion errors as a part of normal operation, as a way to check input or something), there will be warnings that these uses need to be changed into a proper check that always runs. This tells people who are doing the wrong thing to change their code and make it correct. I’m not trying to “let them off” from writing buggy code. I’m warning exactly those people, and telling them how to fix it. What am I misunderstanding here?

1 Like