test: fix TestShell initialization (late follow-up for #30463) #30714

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202408-test-fix_testshell_instantiation changing 1 files +9 −1
  1. theStack commented at 7:18 pm on August 25, 2024: contributor

    Creating a TestShell instance as stated in the docs currently fails on master:

     0$ python3
     1Python 3.10.13 (main, Mar 15 2024, 07:36:23) [Clang 16.0.6 ] on openbsd7
     2Type "help", "copyright", "credits" or "license" for more information.
     3>>> import sys
     4>>> sys.path.insert(0, "/home/thestack/bitcoin/test/functional")
     5>>> from test_framework.test_shell import TestShell
     6>>> test = TestShell().setup(num_nodes=2, setup_clean_chain=True)
     7Traceback (most recent call last):
     8  File "<stdin>", line 1, in <module>
     9  File "/home/thestack/bitcoin/test/functional/test_framework/test_shell.py", line 70, in __new__
    10    TestShell.instance = TestShell.__TestShell()
    11TypeError: BitcoinTestFramework.__init__() missing 1 required positional argument: 'test_file'
    

    Since #30463, BitcoinTestFramework instances expect the path of the calling test at construction, in order to find shared data like the configuration (config.ini) and the cache. Note that in contrast to actual functional tests, we can’t simply pass __file__ here, as the test shell module sits within the test_framework subfolder, so we have to navigate up to the parent directory and append some dummy test file name.

    On the long-term we should probably add some TestShell instantation smoke-test to detect issues like this early. As I’m not too familiar with the CI I’m not sure what is a good way to achieve this (a functional test obviously can’t be used, as that’s already a BitcoinTestFramework test in itself), but happy to take suggestions.

  2. test: fix `TestShell` initialization (late follow-up for #30463) bd7ce05f9d
  3. DrahtBot commented at 7:19 pm on August 25, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK ismaelsadeeq, danielabrozzoni, brunoerg

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

  4. DrahtBot added the label Tests on Aug 25, 2024
  5. theStack commented at 7:23 pm on August 25, 2024: contributor
    cc @hebasto, maybe you have a better idea how to solve this; the current approach works but feels a bit hacky :)
  6. ismaelsadeeq approved
  7. ismaelsadeeq commented at 5:20 pm on August 26, 2024: member

    I verified that this behavior occurs locally:

     0Python 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
     1Type "help", "copyright", "credits" or "license" for more information.
     2>>> import sys
     3>>> sys.path.insert(0, "/Users/abubakarismail/Desktop/bitcoin-dev/bitcoin/test/functional")
     4>>> from test_framework.test_shell import TestShell
     5>>> test = TestShell().setup()
     6Traceback (most recent call last):
     7  File "<stdin>", line 1, in <module>
     8  File "/Users/abubakarismail/Desktop/bitcoin-dev/bitcoin/test/functional/test_framework/test_shell.py", line 70, in __new__
     9    TestShell.instance = TestShell.__TestShell()
    10                         ^^^^^^^^^^^^^^^^^^^^^^^
    11TypeError: BitcoinTestFramework.__init__() missing 1 required positional argument: 'test_file'
    

    This PR bd7ce05f9d9d21903163a2bd9dd2df3ed3990c3e fixes this issue:

    0Python 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
    1Type "help", "copyright", "credits" or "license" for more information.
    2>>> import sys
    3>>> sys.path.insert(0, "/Users/abubakarismail/Desktop/bitcoin-dev/bitcoin/test/functional")
    4>>> from test_framework.test_shell import TestShell
    5>>> test = TestShell().setup()
    62024-08-26T17:08:11.777000Z TestFramework (INFO): PRNG seed is: 8030963347355976194
    72024-08-26T17:08:11.778000Z TestFramework (INFO): Initializing test directory /var/folders/dj/d8p8jhd172n7wnq81ryfl6rc0000gn/T/bitcoin_func_test_tzove0a_
    

    Tested ACK bd7ce05f9d9d21903163a2bd9dd2df3ed3990c3e

    I am neutral on the approach; I only did manual testing for now.

  8. fanquake added the label Needs backport (28.x) on Aug 28, 2024
  9. fanquake requested review from willcl-ark on Aug 28, 2024
  10. danielabrozzoni approved
  11. danielabrozzoni commented at 12:25 pm on August 28, 2024: contributor

    tACK bd7ce05f9d9d21903163a2bd9dd2df3ed3990c3e

    I agree that the approach feels a bit hacky, but I can’t see any other simple way to achieve the same result. This seems good enough, and the fix is pretty isolated :)

  12. achow101 added this to the milestone 28.0 on Aug 29, 2024
  13. brunoerg approved
  14. brunoerg commented at 2:16 pm on August 29, 2024: contributor

    ACK bd7ce05f9d9d21903163a2bd9dd2df3ed3990c3e

    Just verified the fix works fine.

  15. glozow merged this on Aug 29, 2024
  16. glozow closed this on Aug 29, 2024

  17. theStack deleted the branch on Aug 30, 2024
  18. fanquake referenced this in commit 5577d5a3c0 on Aug 30, 2024
  19. fanquake removed the label Needs backport (28.x) on Aug 30, 2024
  20. fanquake commented at 10:17 am on August 30, 2024: member
    Backported to 28.x in #30762.

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: 2024-12-22 00:12 UTC

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