Skip to content

Commit c12a252

Browse files
committed
Merge bitcoin/bitcoin#31415: test: fix TestShell initialization and reset()
303f8cc test: fix TestShell initialization and reset() (Brandon Odiwuor) Pull request description: Fixes TestShell initialization issues caused by resolving symlinks and looking for config.ini in the source path instead of the build path after migration to CMake (see bitcoin/bitcoin#31131 (comment)) https://github.com/bitcoin/bitcoin/blob/ebe4cac38bf6c510b00b8e080acab079c54016d6/test/functional/test_framework/test_shell.py#L77 also fixes bitcoin/bitcoin#31131 **How to test:** ``` $ python3 >>> import sys >>> sys.path.insert(0, "./path/to/bitcoin/build/test/functional") >>> from test_framework.test_shell import TestShell >>> TestShell().setup(num_nodes=2, setup_clean_chain=True) >>> TestShell().shutdown() >>> TestShell.reset() ``` ACKs for top commit: pinheadmz: ACK 303f8cc theStack: Tested ACK 303f8cc pablomartin4btc: re-ACK 303f8cc Tree-SHA512: 25396eb2f7e4bf14426399b1eb3d2c988903ab1f3d38a58f1044b67dd7200c11c01686578fb49b0f2943864166c5c9ccbf122b45202a1e723bf3dbf0c90020fa
2 parents ba0a439 + 303f8cc commit c12a252

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

test/functional/test-shell.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ user inputs. Such environments include the Python3 command line interpreter or
2424

2525
## 2. Importing `TestShell` from the Bitcoin Core repository
2626

27-
We can import the `TestShell` by adding the path of the Bitcoin Core
27+
We can import the `TestShell` by adding the path of the configured Bitcoin Core
2828
`test_framework` module to the beginning of the PATH variable, and then
29-
importing the `TestShell` class from the `test_shell` sub-package.
29+
importing the `TestShell` class from the `test_shell` sub-package. Since
30+
the build system creates a copy of the `test_framework` module into a new `build/`
31+
directory along with the required configuration file, the path to the build copy
32+
must be used.
3033

3134
```
3235
>>> import sys
33-
>>> sys.path.insert(0, "/path/to/bitcoin/test/functional")
36+
>>> sys.path.insert(0, "/path/to/bitcoin/build/test/functional")
3437
>>> from test_framework.test_shell import TestShell
3538
```
3639

@@ -155,7 +158,7 @@ To prevent the logs from being removed after a shutdown, simply set the
155158
The following utility consolidates logs from the bitcoind nodes and the
156159
underlying `BitcoinTestFramework`:
157160

158-
* `/path/to/bitcoin/test/functional/combine_logs.py
161+
* `/path/to/bitcoin/build/test/functional/combine_logs.py
159162
'/path/to/bitcoin_func_test_XXXXXXX'`
160163

161164
## 6. Custom `TestShell` parameters
@@ -170,9 +173,9 @@ can be called after the TestShell is shut down.
170173
| Test parameter key | Default Value | Description |
171174
|---|---|---|
172175
| `bind_to_localhost_only` | `True` | Binds bitcoind P2P services to `127.0.0.1` if set to `True`.|
173-
| `cachedir` | `"/path/to/bitcoin/test/cache"` | Sets the bitcoind datadir directory. |
176+
| `cachedir` | `"/path/to/bitcoin/build/test/cache"` | Sets the bitcoind datadir directory. |
174177
| `chain` | `"regtest"` | Sets the chain-type for the underlying test bitcoind processes. |
175-
| `configfile` | `"/path/to/bitcoin/test/config.ini"` | Sets the location of the test framework config file. |
178+
| `configfile` | `"/path/to/bitcoin/build/test/config.ini"` | Sets the location of the test framework config file. |
176179
| `coveragedir` | `None` | Records bitcoind RPC test coverage into this directory if set. |
177180
| `loglevel` | `INFO` | Logs events at this level and higher. Can be set to `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL`. |
178181
| `nocleanup` | `False` | Cleans up temporary test directory if set to `True` during `shutdown`. |

test/functional/test_framework/test_shell.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def reset(self):
6161
print("Shutdown TestShell before resetting!")
6262
else:
6363
self.num_nodes = None
64-
super().__init__()
64+
dummy_testshell_file = pathlib.Path(__file__).absolute().parent.parent / "testshell_dummy.py"
65+
super().__init__(dummy_testshell_file)
6566

6667
instance = None
6768

@@ -74,8 +75,8 @@ def __new__(cls):
7475
# cache. Since TestShell is meant for interactive use, there is no concrete
7576
# test; passing a dummy name is fine though, as only the containing directory
7677
# is relevant for successful initialization.
77-
tests_directory = pathlib.Path(__file__).resolve().parent.parent
78-
TestShell.instance = TestShell.__TestShell(tests_directory / "testshell_dummy.py")
78+
dummy_testshell_file = pathlib.Path(__file__).absolute().parent.parent / "testshell_dummy.py"
79+
TestShell.instance = TestShell.__TestShell(dummy_testshell_file)
7980
TestShell.instance.running = False
8081
return TestShell.instance
8182

0 commit comments

Comments
 (0)