scripted-diff: replace bare assert == with assert_equal in functional tests #34761

pull Bortlesboat wants to merge 2 commits into bitcoin:master from Bortlesboat:scripted-diff-bare-asserts changing 30 files +92 −89
  1. Bortlesboat commented at 6:01 pm on March 6, 2026: none

    Replace bare assert x == y with assert_equal(x, y) across functional test files for better failure diagnostics.

    Split into two commits per review feedback from @l0rinc:

    1. Manual commit (17 conversions, 14 files): Handles cases requiring new imports (6 files) or complex formatting (spaces in operands, inline comments, list/bytes literals).

    2. Scripted-diff commit (72 conversions, 25 files): Simple \S+ regex matches only single-token operands — no risk of mishandling compound expressions, messages, or comments.

    Lines with assertion messages, and/or compound conditions, and comprehensions are intentionally left unchanged.

    Consolidates the approach from #34752 and #34753 per feedback from @l0rinc.

  2. DrahtBot added the label Refactoring on Mar 6, 2026
  3. DrahtBot commented at 6:01 pm on March 6, 2026: contributor

    ♻️ Automatically closing for now based on heuristics. Please leave a comment, if this was erroneous. Generally, please focus on creating high-quality, original content that demonstrates a clear understanding of the project’s requirements and goals.

    📝 Moderators: If this is spam, please replace the title with ., so that the thread does not appear in search results.

  4. DrahtBot closed this on Mar 6, 2026

  5. Bortlesboat commented at 6:02 pm on March 6, 2026: none

    This was specifically requested by @l0rinc in #34753:

    Please don’t do it file-by-file, if you insist on doing this, make it a scripted-diff across multiple files.

    I closed #34752 and #34753 and consolidated them into this single scripted-diff as suggested. The verify script reproduces the diff exactly. Could this be reopened?

  6. DrahtBot commented at 6:02 pm on March 6, 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.

    Type Reviewers
    Approach NACK l0rinc

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  7. l0rinc commented at 6:24 pm on March 6, 2026: contributor
    Let’s open it again, I want to review this.
  8. Bortlesboat commented at 6:39 pm on March 6, 2026: none
    not sure if i am able to reopen it or the @DrahtBot needs to
  9. sedited reopened this on Mar 6, 2026

  10. DrahtBot added the label CI failed on Mar 6, 2026
  11. in test/functional/wallet_conflicts.py:149 in b57f42b0e8
    145@@ -146,7 +146,7 @@ def test_mempool_conflict(self):
    146 
    147         unspents = alice.listunspent()
    148         assert_equal(len(unspents), 3)
    149-        assert all([tx["amount"] == 25 for tx in unspents])
    150+        assert_equal(all([tx["amount"], 25 for tx in unspents]))
    


    l0rinc commented at 8:27 pm on March 6, 2026:
    please pay more attention and try it out locally before pushing

    Bortlesboat commented at 8:33 pm on March 6, 2026:
    Good catch — the sed regex was too greedy and matched == inside list comprehensions. Fixed by adding / for /b; to the exclusions, which skips any line containing for (comprehensions + generators). Down from 110 to 83 conversions across 30 files. Force-pushed with the corrected scripted-diff.
  12. Bortlesboat force-pushed on Mar 6, 2026
  13. Bortlesboat force-pushed on Mar 7, 2026
  14. Bortlesboat force-pushed on Mar 7, 2026
  15. in test/functional/data/invalid_txs.py:1 in 9631d4056f outdated


    l0rinc commented at 3:58 pm on March 8, 2026:

    sed -i –regexp-extended ‘/ or /b; / and /b; / #/b; / for /b; s/^(\s*)assert ([^,][^=!<>]) == ([^,])$/\1assert_equal(\2, \3)/’ $(git grep -l ‘assert .* == ’ – ’test/functional/’ ‘:(exclude)test/functional/test_framework/’)

    The point of the scripted diff is to help the reviewer be more confident in the changes. This vibe-regex doesn’t help me with that. But we should be able to do it in two commits instead: the first one covering the values that a simple regex cannot reliably detect (e.g. because of complicated formatting or new imports). The second commit could be a simple regex via sed/grep/python for the remaining trivial cases.


    Bortlesboat commented at 4:58 pm on March 8, 2026:

    Good call — restructured into two commits:

    1. Manual commit: adds imports, converts lines with spaces in operands, inline comments, list/bytes literals (17 conversions)
    2. Scripted-diff using \S+ — only matches single-token operands, so no exclusion heuristics needed:
    0sed -i --regexp-extended 's/^(\s*)assert (\S+) == (\S+)$/\1assert_equal(\2, \3)/' \
    1  $(git grep -l 'assert [^ ]* == [^ ]*$' -- 'test/functional/' ':(exclude)test/functional/test_framework/')
    
  16. in test/functional/feature_posix_fs_permissions.py:25 in 9631d4056f outdated
    21@@ -22,12 +22,12 @@ def skip_test_if_missing_module(self):
    22     def check_directory_permissions(self, dir):
    23         mode = os.lstat(dir).st_mode
    24         self.log.info(f"{stat.filemode(mode)} {dir}")
    25-        assert mode == (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
    26+        assert_equal(mode, (stat.S_IFDIR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR))
    


    l0rinc commented at 4:27 pm on March 8, 2026:
    Have you tried this locally? This is missing a from test_framework.util import assert_equal

    Bortlesboat commented at 4:58 pm on March 8, 2026:
    Fixed — added the missing import. All 6 files that needed new assert_equal imports are handled in commit 1 now. Verified with py_compile across all 30 changed files.
  17. l0rinc changes_requested
  18. l0rinc commented at 4:31 pm on March 8, 2026: contributor

    Approach NACK

    Lots of tests are failing, it’s obvious you haven’t even tried it locally:

     0feature_fee_estimation.py                                                        |  Failed  | 250 s
     1feature_posix_fs_permissions.py                                                  |  Failed  | 1 s                                                                                               
     2feature_reindex.py                                                               |  Failed  | 38 s                                                                                              
     3feature_reindex_readonly.py                                                      |  Failed  | 2 s                                                                                               
     4mempool_updatefromblock.py                                                       |  Failed  | 282 s                                                                                             
     5mining_getblocktemplate_longpoll.py                                              |  Failed  | 2 s                                                                                               
     6p2p_handshake.py                                                                 |  Failed  | 3 s                                                                                               
     7p2p_handshake.py --v2transport                                                   |  Failed  | 3 s                                                                                               
     8p2p_headers_sync_with_minchainwork.py                                            |  Failed  | 228 s                                                                                             
     9p2p_invalid_tx.py --v1transport                                                  |  Failed  | 5 s                                                                                               
    10p2p_invalid_tx.py --v2transport                                                  |  Failed  | 5 s                                                                                               
    11wallet_disable.py                                                                |  Failed  | 1 s 
    

    Now that’s I’ve spent time with this, I will push an alternative PR instead of babysitting this one.

  19. test: manually convert assert == requiring new imports or complex formatting
    Convert assert == to assert_equal() for cases that cannot be handled by
    a simple scripted-diff regex:
    
    - Add assert_equal import to 6 files that were missing it
    - Convert lines with spaces in operands (arithmetic, bitwise, stat flags)
    - Convert lines with inline comments (preserving the comments)
    - Convert lines with list/bytes literals containing commas or spaces
    
    Lines with assertion messages, compound conditions (and/or), and
    comprehensions are intentionally left unchanged.
    52cdb5f0b5
  20. scripted-diff: replace bare assert == with assert_equal in functional tests
    Replace remaining simple assert x == y with assert_equal(x, y) for
    better failure diagnostics. Only matches single-token operands (no
    spaces), so compound expressions, assertion messages, and inline
    comments are unaffected.
    
    -BEGIN VERIFY SCRIPT-
    sed -i --regexp-extended 's/^(\s*)assert (\S+) == (\S+)$/\1assert_equal(\2, \3)/' $(git grep -l 'assert [^ ]* == [^ ]*$' -- 'test/functional/' ':(exclude)test/functional/test_framework/')
    -END VERIFY SCRIPT-
    04a8cb6ae5
  21. Bortlesboat force-pushed on Mar 8, 2026
  22. Bortlesboat commented at 4:52 pm on March 8, 2026: none

    Force-pushed with the two-commit approach:

    Commit 1 (manual): Adds assert_equal imports to the 6 files that were missing them, and converts 17 lines that have complex formatting (spaces in operands, inline comments, list/bytes literals). Not a scripted-diff — reviewer can inspect each change directly.

    Commit 2 (scripted-diff): Uses \S+ to match only single-token operands — no spaces means no risk of matching compound expressions, assertion messages, or inline comments. The verify script is one sed command:

    0sed -i --regexp-extended 's/^(\s*)assert (\S+) == (\S+)$/\1assert_equal(\2, \3)/' \
    1  $(git grep -l 'assert [^ ]* == [^ ]*$' -- 'test/functional/' ':(exclude)test/functional/test_framework/')
    

    72 conversions across 25 files in the scripted-diff, 17 manual conversions in commit 1. Lines with assertion messages, and/or compound conditions, and comprehensions are left unchanged.

    Sorry for the noise on the earlier pushes — should have caught the missing imports before pushing.

  23. sedited commented at 5:01 pm on March 8, 2026: contributor
    Maybe try to review some other pull requests locally first before contributing a change yourself. You are required to run the tests and understand what they in the context of your change before opening a pull request. We generally also don’t accept trivial refactoring PRs from fresh contributors, see the contributing guidelines: https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#refactoring .
  24. sedited closed this on Mar 8, 2026


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