diff options
Diffstat (limited to 'packages/meshbay-node/tests/conftest.py')
| -rw-r--r-- | packages/meshbay-node/tests/conftest.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/meshbay-node/tests/conftest.py b/packages/meshbay-node/tests/conftest.py index 2ca0c8a..9ef23a3 100644 --- a/packages/meshbay-node/tests/conftest.py +++ b/packages/meshbay-node/tests/conftest.py @@ -92,3 +92,26 @@ def opened_ack(session, msg: dict) -> dict: ctx = session._group_ctx() return file_upload_ack_payload(ctx["gek"], session._group_id or "", msg) + + +def patch_cli(monkeypatch, name: str, value) -> None: + """Replace `name` wherever `meshbay-node`'s command line reads it. + + Each module of `meshbay_node.cli` imports what it uses by name, so a helper + like `_daemon_api` is bound once in every module that calls it, and patching + the one that defines it leaves the verbs calling the real thing — which + talks to whatever node is running on this machine. `daemon` is included: + its `main()` still reads the config path when no verb is given. + """ + import importlib + import pkgutil + + import meshbay_node.cli as cli + from meshbay_node import daemon + + modules = [daemon] + [importlib.import_module(f"meshbay_node.cli.{m.name}") + for m in pkgutil.iter_modules(cli.__path__)] + holders = [m for m in modules if hasattr(m, name)] + assert holders, f"no module of the CLI has {name!r} to patch" + for module in holders: + monkeypatch.setattr(module, name, value) |