qa: assert_equals -> assert_true/assert_false

bitcoin/bitcoin: PR #36257

2 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · assert_true and assert_false omit the checked value from failures

The new functional-test helpers omit the actual value from assertion failures, making unexpected non-boolean results harder to diagnose than with the replaced assert_equal calls.

Location: test/functional/test_framework/util.py:91 (head).

Details and suggested fix

For example, the converted assert_true(info.get('solvable')) in wallet_address_types.py now reports the same failure for a missing key (None) and a False field; previously, assert_equal printed the actual operand. For genuinely boolean inputs the lost information is small, and RPC results may remain recoverable from authproxy debug logs, but those logs do not cover arbitrary Python expressions. Include {expression!r} in both failure messages, for example raise AssertionError(f"Expression was not True: {expression!r}"). This preserves the identity checks and explicit raises, so acceptance behavior and optimization resistance remain unchanged.


Link

[suggestion] · Import preparation mixes required additions with unrelated formatting

The hand-edited import-preparation commit also moves and reindents existing imports, adding manual comparison work before the scripted conversion.

Location: test/functional/rpc_blockchain.py:58 at a9f7e190010b (commit) (commit).

Details and suggested fix

Compared with its direct parent 7617d6da35b90cebda94884bc416d82235d19380, import-preparation commit a9f7e190010b183d89baa9312befb415128f241b reorders assert_not_equal, assert_is_hex_string and assert_is_hash_string in rpc_blockchain.py, and reindents the existing import block in wallet_reorgsrestore.py. These changes make reviewers compare existing import sets as well as check the required additions. Keep this preparation commit before scripted conversion 74e8803ac9920bf20274f524736803a26342e468, but limit it to the needed assert_true and assert_false additions. Move the unrelated sorting and indentation changes to a separate commit, or omit them. This preserves the conversion's prerequisites and behavior while making the manual patch easier to validate, consistent with the separation requested in CONTRIBUTING.md.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

#31874 deferred assert_true rather than recording a settled rejection of it. l0rinc requested separating the dormant-check fix from introducing another assertion helper, and suggested proposing the helper with a scripted conversion so its readability benefit could be judged. The author eventually removed it, explicitly saying the proposal would be left for later.

The earlier decision concerned scope and establishing a test-writing convention. The author had argued that putting the expected boolean at the beginning was easier to read for long expressions—the same readability consideration relevant to this migration. The withdrawal statement does not identify strict boolean identity as the reason for removal.

Source 1 · Source 2 · Source 3 · Source 4

A separate explicit objection concerned the optimization rationale: maflcko questioned whether anyone actually ran functional tests with assertions optimized out, argued that this concern could instead be handled by failing early at startup, and said a project-wide replacement would need enforcement. The subsequent approach NACK specifically cited these outstanding PYTHONOPTIMIZE questions.

The new pinned assert_true documents that it cannot be optimized away. Historically, that property did not by itself settle whether a new helper or a broader assertion convention was warranted. The author acknowledged optimized test runs were rare and expressed openness to a startup error.

Source 1 · Source 2 · Source 3 · Source 4

Boolean semantics were discussed, but the concrete objection was that the earlier helper accepted non-boolean truthy values. maflcko pointed out that assert_true("abc") and integral values such as 3 would pass. The author added boolean type annotations and cited mypy checking; l0rinc replied that annotations were only hints and assert_true(1) would still pass at runtime. The author acknowledged that limitation.

This is not a historical objection to strict boolean identity. It was concern about a helper named assert_true retaining truthiness behavior despite annotations. The pinned current helper instead explicitly checks identity with True or False, so the earlier runtime examples and the current behavior must be distinguished.

Source 1 · Source 2 · Source 3 · Source 4

Ralph's inferences

The earlier withdrawal should not be interpreted as choosing equality semantics over strict boolean identity. The inspected discussion supports a deferral amid scope, optimization-policy, and truthiness concerns, not a resolution of identity versus equality. Independently, the pinned code establishes that the current migration changes that distinction: assert_equal uses !=, while the new helpers use is not True/False. Consequently, numeric 1 and 0 can satisfy the corresponding existing equality assertions but not the new identity assertions.

This separates the historical reason for retaining the old convention from the semantic difference introduced by the current shared API, without treating the prior deferral as endorsement or rejection of that difference.

Source 1 · Source 2 · Source 3 · Source 4

Unresolved disagreements

The inspected #31874 record does not settle whether the functional-test convention should require runtime boolean identity, permit equality-compatible values, or retain truthiness. The response to the non-boolean examples was annotations and discussion of linting, followed by removal of the helper—not an explicit resolution of those alternatives.

There is relevant historical discussion about typing, but no documented prior decision establishing the exact boolean contract now implemented by assert_true/assert_false.

Source 1 · Source 2 · Source 3 · Source 4 · Source 5