Skip to content

Conversation

theStack
Copy link
Contributor

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

$ python3
Python 3.10.13 (main, Mar 15 2024, 07:36:23) [Clang 16.0.6 ] on openbsd7
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.insert(0, "/home/thestack/bitcoin/test/functional")
>>> from test_framework.test_shell import TestShell
>>> test = TestShell().setup(num_nodes=2, setup_clean_chain=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/thestack/bitcoin/test/functional/test_framework/test_shell.py", line 70, in __new__
    TestShell.instance = TestShell.__TestShell()
TypeError: 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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 25, 2024

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.

@DrahtBot DrahtBot added the Tests label Aug 25, 2024
@theStack
Copy link
Contributor Author

cc @hebasto, maybe you have a better idea how to solve this; the current approach works but feels a bit hacky :)

Copy link
Member

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that this behavior occurs locally:

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

This PR bd7ce05 fixes this issue:

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

Tested ACK bd7ce05

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

Copy link
Contributor

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK bd7ce05

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 :)

@achow101 achow101 added this to the 28.0 milestone Aug 29, 2024
Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bd7ce05

Just verified the fix works fine.

@glozow glozow merged commit 1e48238 into bitcoin:master Aug 29, 2024
16 checks passed
@theStack theStack deleted the 202408-test-fix_testshell_instantiation branch August 30, 2024 08:06
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Aug 30, 2024
@fanquake fanquake mentioned this pull request Aug 30, 2024
@fanquake
Copy link
Member

Backported to 28.x in #30762.

achow101 added a commit that referenced this pull request Sep 5, 2024
b2a1379 depends: build libevent with -D_GNU_SOURCE (fanquake)
199bb09 test: fixing failing system_tests/run_command under some Locales (Jadi)
342baab test: Avoid intermittent timeout in p2p_headers_sync_with_minchainwork.py (MarcoFalke)
5577d5a test: fix `TestShell` initialization (late follow-up for #30463) (Sebastian Falbesoner)

Pull request description:

  Backports:
  * #30714
  * #30743
  * #30761
  * #30788

ACKs for top commit:
  willcl-ark:
    ACK b2a1379
  achow101:
    ACK b2a1379
  stickies-v:
    ACK b2a1379

Tree-SHA512: bf08ac0c613395def974a1b287345d4a64edc066c14f8c9f0184478b0e33e48333760eeb6e96b6b5fbafbb21b40d01875e3f526213a2734e226b2e111d71f3a3
@bitcoin bitcoin locked and limited conversation to collaborators Aug 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants