From 303f8cca0568d2ca77189c4eccdfc7a6913c958d Mon Sep 17 00:00:00 2001 From: Brandon Odiwuor Date: Tue, 3 Dec 2024 12:42:56 +0300 Subject: [PATCH] test: fix TestShell initialization and reset() --- test/functional/test-shell.md | 15 +++++++++------ test/functional/test_framework/test_shell.py | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test/functional/test-shell.md b/test/functional/test-shell.md index d79c4a0ab69..0a05658e2f8 100644 --- a/test/functional/test-shell.md +++ b/test/functional/test-shell.md @@ -24,13 +24,16 @@ user inputs. Such environments include the Python3 command line interpreter or ## 2. Importing `TestShell` from the Bitcoin Core repository -We can import the `TestShell` by adding the path of the Bitcoin Core +We can import the `TestShell` by adding the path of the configured Bitcoin Core `test_framework` module to the beginning of the PATH variable, and then -importing the `TestShell` class from the `test_shell` sub-package. +importing the `TestShell` class from the `test_shell` sub-package. Since +the build system creates a copy of the `test_framework` module into a new `build/` +directory along with the required configuration file, the path to the build copy +must be used. ``` >>> import sys ->>> sys.path.insert(0, "/path/to/bitcoin/test/functional") +>>> sys.path.insert(0, "/path/to/bitcoin/build/test/functional") >>> from test_framework.test_shell import TestShell ``` @@ -155,7 +158,7 @@ To prevent the logs from being removed after a shutdown, simply set the The following utility consolidates logs from the bitcoind nodes and the underlying `BitcoinTestFramework`: -* `/path/to/bitcoin/test/functional/combine_logs.py +* `/path/to/bitcoin/build/test/functional/combine_logs.py '/path/to/bitcoin_func_test_XXXXXXX'` ## 6. Custom `TestShell` parameters @@ -170,9 +173,9 @@ can be called after the TestShell is shut down. | Test parameter key | Default Value | Description | |---|---|---| | `bind_to_localhost_only` | `True` | Binds bitcoind P2P services to `127.0.0.1` if set to `True`.| -| `cachedir` | `"/path/to/bitcoin/test/cache"` | Sets the bitcoind datadir directory. | +| `cachedir` | `"/path/to/bitcoin/build/test/cache"` | Sets the bitcoind datadir directory. | | `chain` | `"regtest"` | Sets the chain-type for the underlying test bitcoind processes. | -| `configfile` | `"/path/to/bitcoin/test/config.ini"` | Sets the location of the test framework config file. | +| `configfile` | `"/path/to/bitcoin/build/test/config.ini"` | Sets the location of the test framework config file. | | `coveragedir` | `None` | Records bitcoind RPC test coverage into this directory if set. | | `loglevel` | `INFO` | Logs events at this level and higher. Can be set to `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL`. | | `nocleanup` | `False` | Cleans up temporary test directory if set to `True` during `shutdown`. | diff --git a/test/functional/test_framework/test_shell.py b/test/functional/test_framework/test_shell.py index e232430507b..3f237c7ea20 100644 --- a/test/functional/test_framework/test_shell.py +++ b/test/functional/test_framework/test_shell.py @@ -61,7 +61,8 @@ class TestShell: print("Shutdown TestShell before resetting!") else: self.num_nodes = None - super().__init__() + dummy_testshell_file = pathlib.Path(__file__).absolute().parent.parent / "testshell_dummy.py" + super().__init__(dummy_testshell_file) instance = None @@ -74,8 +75,8 @@ class TestShell: # cache. Since TestShell is meant for interactive use, there is no concrete # test; passing a dummy name is fine though, as only the containing directory # is relevant for successful initialization. - tests_directory = pathlib.Path(__file__).resolve().parent.parent - TestShell.instance = TestShell.__TestShell(tests_directory / "testshell_dummy.py") + dummy_testshell_file = pathlib.Path(__file__).absolute().parent.parent / "testshell_dummy.py" + TestShell.instance = TestShell.__TestShell(dummy_testshell_file) TestShell.instance.running = False return TestShell.instance