test: migrate functional test equality asserts to assert_equal #34773

pull l0rinc wants to merge 8 commits into bitcoin:master from l0rinc:l0rinc/test-assert-equal changing 59 files +215 −178
  1. l0rinc commented at 10:22 pm on March 8, 2026: contributor

    Problem

    Plain assert x == y is a poor fit for this test framework, assert_equal() gives more useful failure output and keeps equality checks consistent with the rest of the functional tests.

    Design

    A simple scripted diff cannot safely rewrite all of them because many files use == inside larger expressions, such as chained conditions, comprehensions, and other compound assertions. That makes a one-shot mechanical conversion either incorrect or harder to review.

    Fix

    Nerd-sniped by #34761, this series first rewrites the non-mechanical cases into simpler assertions so they stand on their own and failures are easier to identify, converging on a simple scripted diff that is straightforward to verify.

    The stack is structured so the manual cleanup comes first, the import-only setup comes immediately before it, and the final commit only touches the cases that are safe to rewrite mechanically.

  2. test: use `in` for two-value equality asserts
    Some tests spell a two-value membership check as `assert x == a or x == b`.
    Rewrite those sites as `assert x in (a, b)`.
    This keeps the check the same and removes `==` forms that the later cleanup should not touch.
    29e5e9ca37
  3. test: split equality asserts joined by `and`
    Some tests combine multiple equality checks in one `assert`.
    Split those checks into separate assertions so failures point at the exact mismatch.
    This also removes mixed `==` expressions that the later cleanup should not touch.
    ce038e850d
  4. test: simplify boolean equality asserts
    Some tests compare booleans to `True` or `False`, or compare lengths to zero.
    Rewrite those sites to direct truthiness checks.
    This keeps the behavior and removes more non-target `==` forms before the later cleanup.
    068333c5c3
  5. test: prep manual equality assert conversions
    The later scripted diff only handles plain `assert x == y` lines.
    Some remaining tests still use equality inside comprehensions, parenthesized asserts, and other shapes that the line-based rewrite would misread.
    Rewrite those sites by hand first so the later mechanical conversion stays safe.
    The commit also simplifies the dead `len(["errors"]) == 0` branch in `blocktools.py`, which can never be true.
    5e4f9eb755
  6. test: convert equality asserts with comments or special chars
    Some remaining `assert x == y` lines include inline comments, list literals, or descriptor strings with `#`.
    Convert those sites by hand so the later mechanical rewrite can stay simple.
    1d40323477
  7. test: convert simple equality asserts in excluded files
    A few files still need to stay out of the later scripted diff because they contain more complicated assert shapes.
    Convert the straightforward equality checks in those files by hand first.
    Use a local import in `authproxy.py` so the change does not create an import cycle.
    abe2814d9a
  8. DrahtBot added the label Tests on Mar 8, 2026
  9. DrahtBot commented at 10:23 pm on March 8, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  10. test: add missing `assert_equal` imports
    The later scripted diff only rewrites call sites.
    Add `assert_equal` imports in the remaining files that still need them so the mechanical replacement can apply cleanly.
    97e4fe8316
  11. scripted-diff: replace remaining Python test equality asserts
    Some Python functional tests still use plain `assert x == y`.
    The earlier commits convert the ambiguous assert patterns by hand, so this commit can rewrite the remaining safe cases mechanically.
    The verify script excludes `wallet_bumpfee.py`, `test_framework/netutil.py`, and `test_framework/authproxy.py`, which still contain assert forms that the plain line-based substitution would misidentify.
    
    -BEGIN VERIFY SCRIPT-
    perl -pi -e 's/^(\s*)assert (.+?) == ([^,#]+?)$/\1assert_equal(\2, \3)/' $(git ls-files -- 'test/functional' \
    ':(exclude)test/functional/wallet_bumpfee.py' ':(exclude)test/functional/test_framework/netutil.py' ':(exclude)test/functional/test_framework/authproxy.py')
    -END VERIFY SCRIPT-
    c94141c39b
  12. l0rinc force-pushed on Mar 8, 2026
  13. DrahtBot added the label CI failed on Mar 8, 2026
  14. DrahtBot removed the label CI failed on Mar 8, 2026


l0rinc DrahtBot

Labels
Tests


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-03-09 09:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me