mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Merge bitcoin/bitcoin#22201: test: Fix TestShell to allow running in Jupyter Notebook
168b6c317c
add dummy file param to fix jupyter (Josiah Baker) Pull request description: this fixes argparse to use `parse_known_args`. previously, if an unknown argument was passed, argparse would fail with an `unrecognized arguments: %s` error. ## why the documentation mentions being able to run `TestShell` in a REPL interpreter or a jupyter notebook. when i tried to run inside a jupyter notebook, i got the following error: ![image](https://user-images.githubusercontent.com/7444140/121382910-57554880-c947-11eb-94f2-49da8679528c.png) this was due to the notebook passing the filename of the notebook as an argument. this is a known problem with notebooks and argparse, documented here: https://stackoverflow.com/questions/48796169/how-to-fix-ipykernel-launcher-py-error-unrecognized-arguments-in-jupyter ## testing to test, make sure you have jupyter notebooks installed. you can do this by running: ``` pip install notebook ``` or following instructions from [here](https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html). once installed, start a notebook (`jupyter notebook`), launch a python3 kernel and run the following snippet: ```python import sys # make sure this is the path for your system sys.path.insert(0, "/path/to/bitcoin/test/functional") from test_framework.test_shell import TestShell test = TestShell().setup(num_nodes=2, setup_clean_chain=True) ``` you should see the following output, without errors: ![image](https://user-images.githubusercontent.com/7444140/121383301-a307f200-c947-11eb-83b6-6c50b2cada25.png) if you are unfamiliar with notebooks, here is a short guide on using them: https://jupyter.readthedocs.io/en/latest/running.html ACKs for top commit: MarcoFalke: review ACK168b6c317c
jamesob: crACK168b6c317c
practicalswift: cr ACK168b6c317c
Tree-SHA512: 4fee1563bf64a1cf9009934182412446cde03badf2f19553b78ad2cb3ceb0e5e085a5db41ed440473494ac047f04641311ecbba3948761c6553d0ca4b54937b4
This commit is contained in:
commit
672870ab7b
1 changed files with 4 additions and 0 deletions
|
@ -194,6 +194,10 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
help="Run test using legacy wallets", dest='descriptors')
|
||||
|
||||
self.add_options(parser)
|
||||
# Running TestShell in a Jupyter notebook causes an additional -f argument
|
||||
# To keep TestShell from failing with an "unrecognized argument" error, we add a dummy "-f" argument
|
||||
# source: https://stackoverflow.com/questions/48796169/how-to-fix-ipykernel-launcher-py-error-unrecognized-arguments-in-jupyter/56349168#56349168
|
||||
parser.add_argument("-f", "--fff", help="a dummy argument to fool ipython", default="1")
|
||||
self.options = parser.parse_args()
|
||||
self.options.previous_releases_path = previous_releases_path
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue