From 318b2a2f90dfd8ae20beca58e55e6d240a7f3d27 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 | 9 ++++++--- test/functional/test_framework/test_shell.py | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/test/functional/test-shell.md b/test/functional/test-shell.md index d79c4a0ab69..a9c1d9f5c9d 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 ``` diff --git a/test/functional/test_framework/test_shell.py b/test/functional/test_framework/test_shell.py index e232430507b..b37fbc48fb7 100644 --- a/test/functional/test_framework/test_shell.py +++ b/test/functional/test_framework/test_shell.py @@ -7,6 +7,14 @@ import pathlib from test_framework.test_framework import BitcoinTestFramework +# BitcoinTestFramework instances are supposed to be constructed with the path +# of the calling test in order to find shared data like configuration and the +# 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__).absolute().parent.parent +dummy_testshell_file = tests_directory / "testshell_dummy.py" + class TestShell: """Wrapper Class for BitcoinTestFramework. @@ -61,7 +69,7 @@ class TestShell: print("Shutdown TestShell before resetting!") else: self.num_nodes = None - super().__init__() + super().__init__(dummy_testshell_file) instance = None @@ -69,13 +77,7 @@ class TestShell: # This implementation enforces singleton pattern, and will return the # previously initialized instance if available if not TestShell.instance: - # BitcoinTestFramework instances are supposed to be constructed with the path - # of the calling test in order to find shared data like configuration and the - # 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") + TestShell.instance = TestShell.__TestShell(dummy_testshell_file) TestShell.instance.running = False return TestShell.instance