test: [move-only] binary utils to utils.py #33633

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2510-test-mv-util changing 2 files +99 −92
  1. maflcko commented at 12:41 pm on October 15, 2025: member

    Having the binary related utils sit in the test_framework.py is fine. However, they are mostly stand-alone utils, which may be used externally.

    So move them to utils.py, to allow easier external use. The diff is trivial and can be reviewed via the git options --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space.

  2. test: Move get_binary_paths and Binaries to util.py
    Can be reviewed with the git options
    --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
    fa9f495308
  3. test: Move export_env_build_path to util.py fa75ef4328
  4. DrahtBot added the label Tests on Oct 15, 2025
  5. DrahtBot commented at 12:41 pm on October 15, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33633.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK kevkevinpal, Sjors, janb84, musaHaruna, yuvicc, enirox001
    Concept ACK l0rinc

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #33142 (test: Run bench sanity checks in parallel with functional tests by maflcko)
    • #32928 (test: add logging to mock external signers by Sjors)
    • #31723 (node: Add –debug_runs/-waitfordebugger + –debug_cmd by hodlinator)
    • #30437 (ipc: add bitcoin-mine test program by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  6. in test/functional/test_framework/test_framework.py:230 in fa75ef4328
    253 
    254     def setup(self):
    255         """Call this method to start up the test framework object with options set."""
    256 
    257         check_json_precision()
    258+        export_env_build_path(self.config)
    


    kevkevinpal commented at 7:11 pm on October 15, 2025:

    is there a reason why you moved this logic above this line of code?

    self.options.cachedir = os.path.abspath(self.options.cachedir)


    maflcko commented at 7:21 pm on October 15, 2025:
    i don’t think the order matters, because the two lines are completely unrelated and independent

    kevkevinpal commented at 7:23 pm on October 15, 2025:
    No problem was just checking to see if there was a reason for it
  7. kevkevinpal commented at 7:13 pm on October 15, 2025: contributor

    ACK fa75ef4

    Looks straightforward to me and makes sense to move those functions outside of the test framework to be used externally

  8. Sjors commented at 9:29 am on October 16, 2025: member
    lgtm ACK fa75ef4328f638221bcf85fcbefa885122084622
  9. janb84 commented at 12:53 pm on October 16, 2025: contributor

    ACK fa75ef4328f638221bcf85fcbefa885122084622

    Pr moves Helper class for information about bitcoin binaries to util.py. To move the a helper class outside Test framework makes sense to me, this cleans up the test_framework.py code

    Not completely convinced that these functions in the helper class will be used externally due to the tight coupling with these config settings config["environment"]["BUILDDIR"], bin", (this could be a good follow-up, if needed by external testers)

  10. yuvicc commented at 1:08 pm on October 16, 2025: contributor

    Code review ACK fa75ef4328f638221bcf85fcbefa885122084622

    The Binaries class and get_binary_paths() are logically separate from TestFramework orchestration, so moving them to util.py makes sense for modularity.

    As mentioned by @janb84, the tight coupling with config["environment"]["BUILDDIR"] and related settings means external usage still requires test framework. Not blocking for this PR, but worth considering for future refactoring if there’s the requirement.

  11. maflcko commented at 1:11 pm on October 16, 2025: member
    The config is written by the build system, so I don’t think it is coupled with the TestFramework class itself.
  12. l0rinc commented at 5:32 pm on October 16, 2025: contributor
    Concept ACK
  13. musaHaruna commented at 8:32 am on October 17, 2025: none

    Code Review ACK fa75ef4

    PR looks straight forward, moving binaries to util.py files, help make them reusable and not bound to the Test framework.

    The config is written by the build system, so I don’t think it is coupled with the TestFramework class itself.

    Also confirmed that the config is written by the build system located at bitcoin/build/test/config.ini. From my understanding, bitcoin/test/config.ini.in is a blueprint that gets filled in with real build info like [environment] and [components] after compilation.

    Example after building:

     0[environment]
     1CLIENT_NAME=Bitcoin Core
     2CLIENT_BUGREPORT=https://github.com/bitcoin/bitcoin/issues
     3SRCDIR=/home/user-name/bitcoin
     4BUILDDIR=/home/user-name/bitcoin/build
     5EXEEXT=
     6RPCAUTH=/home/user-name/bitcoin/share/rpcauth/rpcauth.py
     7
     8[components]
     9ENABLE_WALLET=true
    10ENABLE_CLI=true
    
  14. DrahtBot requested review from l0rinc on Oct 17, 2025
  15. in test/functional/test_framework/util.py:318 in fa75ef4328
    313+        default_filename = os.path.join(
    314+            config["environment"]["BUILDDIR"],
    315+            "bin",
    316+            binary + config["environment"]["EXEEXT"],
    317+        )
    318+        setattr(paths, env_variable_name.lower(), os.getenv(env_variable_name, default=default_filename))
    


    janb84 commented at 8:56 am on October 17, 2025:

    Just to clarify, i’m not saying that it is coupled to the test_framework, but that it is coupled to the config. For a followup I could see something like the code below, for this PR I like that it is more or less a code move.

    Rough example; not ment to be a nit:

     0def get_binary_paths(bin_path, exe_ext):
     1    """Get paths of all binaries from environment variables or their default values"""
     2
     3    paths = types.SimpleNamespace()
     4    binaries = {
     5        "bitcoin": "BITCOIN_BIN",
     6        "bitcoind": "BITCOIND",
     7        "bitcoin-cli": "BITCOINCLI",
     8        "bitcoin-util": "BITCOINUTIL",
     9        "bitcoin-tx": "BITCOINTX",
    10        "bitcoin-chainstate": "BITCOINCHAINSTATE",
    11        "bitcoin-wallet": "BITCOINWALLET",
    12    }
    13    # Set paths to bitcoin core binaries allowing overrides with environment
    14    # variables.
    15    for binary, env_variable_name in binaries.items():
    16        default_filename = os.path.join(
    17            bin_path,
    18            binary + exe_ext,
    19        )
    20        setattr(paths, env_variable_name.lower(), os.getenv(env_variable_name, default=default_filename))
    

    maflcko commented at 9:01 am on October 17, 2025:
    thx, I’ll leave as-is for now, but this can certainly be pushed in the future, if and once there is additional need to uncouple from the config
  16. yuvicc commented at 6:32 am on October 20, 2025: contributor
    LGTM ACK fa75ef4328f638221bcf85fcbefa885122084622
  17. in test/functional/test_framework/util.py:325 in fa75ef4328
    321@@ -322,6 +322,13 @@ def get_binary_paths(config):
    322     return paths
    323 
    324 
    325+def export_env_build_path(config):
    


    enirox001 commented at 5:26 pm on October 20, 2025:

    nano nit:

    consider adding a docstring to the new export_env_build_path function. Its purpose was clear in the old context, but a comment would be helpful now that it’s a standalone utility.

  18. enirox001 commented at 5:29 pm on October 20, 2025: contributor

    ACK fa75ef4

    Reviewed the commits, and this is a solid refactor. Moving the standalone binary helpers out of the large test_framework.py and into util.py is a welcome change for modularity and separation of concerns

  19. fanquake merged this on Oct 21, 2025
  20. fanquake closed this on Oct 21, 2025

  21. maflcko deleted the branch on Oct 21, 2025

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: 2025-10-31 18:13 UTC

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