Skip to content

Commit 808c346

Browse files
authored
fix: Use process context manager when running in CLI (#125)
# Summary Closes #124, ensuring that the `destroy()` method gets called when running a process via the CLI. # Changes * Use context manager for running `Process` in CLI.
1 parent bb91583 commit 808c346

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

plugboard/cli/process/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def _build_process(config: ConfigSpec) -> Process:
3939

4040

4141
async def _run_process(process: Process) -> None:
42-
await process.init()
43-
await process.run()
42+
async with process:
43+
await process.run()
4444

4545

4646
@app.command()

tests/unit/test_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ def test_cli_process_run() -> None:
2222
# Process must be built
2323
mock_process_builder.build.assert_called_once()
2424
# Process must be initialised
25-
mock_process.init.assert_called_once()
25+
mock_process.__aenter__.assert_called_once()
2626
# Process must be run
2727
mock_process.run.assert_called_once()
28+
# Process must be destroyed
29+
mock_process.__aexit__.assert_called_once()
2830

2931

3032
def test_cli_process_diagram() -> None:

0 commit comments

Comments
 (0)