Skip to content

Commit 801ace9

Browse files
test: fix unawaited coroutine warnings in test suite
Close abandoned coroutines to prevent RuntimeWarning emissions during garbage collection: - test_cli_commands.py: Patch async_main in TestMain tests so no real coroutine is created when asyncio.run is mocked - test_tui_actions.py: Close AsyncMock coroutines in TestRunCommand tests after guard-clause early returns and captured-but-unrun workers - test_tui_screens.py: Close _do_credential_login coroutine passed to mocked run_worker in TestAuthScreen tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 866240f commit 801ace9

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

tests/test_cli_commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ def test_main_calls_async_main(self):
14221422
with (
14231423
patch("flameconnect.cli.build_parser") as mock_parser_fn,
14241424
patch("flameconnect.cli.asyncio") as mock_asyncio,
1425+
patch("flameconnect.cli.async_main", new=MagicMock()),
14251426
):
14261427
mock_parser = MagicMock()
14271428
mock_args = argparse.Namespace(command="list", verbose=False)
@@ -1436,6 +1437,7 @@ def test_main_verbose_logging(self):
14361437
with (
14371438
patch("flameconnect.cli.build_parser") as mock_parser_fn,
14381439
patch("flameconnect.cli.asyncio"),
1440+
patch("flameconnect.cli.async_main", new=MagicMock()),
14391441
patch("flameconnect.cli.logging") as mock_logging,
14401442
):
14411443
import logging as real_logging
@@ -1455,6 +1457,7 @@ def test_main_no_verbose_logging(self):
14551457
with (
14561458
patch("flameconnect.cli.build_parser") as mock_parser_fn,
14571459
patch("flameconnect.cli.asyncio"),
1460+
patch("flameconnect.cli.async_main", new=MagicMock()),
14581461
patch("flameconnect.cli.logging") as mock_logging,
14591462
):
14601463
import logging as real_logging

tests/test_tui_actions.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,29 +2308,44 @@ async def test_no_op_when_not_dashboard(self, mock_client):
23082308
non_dashboard = MagicMock(spec=[])
23092309
app = _make_app(mock_client, non_dashboard)
23102310

2311-
coro = AsyncMock()()
2311+
async def _noop():
2312+
pass
2313+
2314+
coro = _noop()
23122315

23132316
with patch.object(type(app), "screen", new_callable=PropertyMock) as prop:
23142317
prop.return_value = non_dashboard
23152318
app._run_command(coro, "test...", "test failed")
23162319

23172320
# run_worker should not have been called
23182321
assert len(app._captured_workers) == 0
2322+
coro.close()
23192323

23202324
async def test_sets_write_in_progress(self, mock_client, mock_dashboard):
23212325
app = _make_app(mock_client, mock_dashboard)
2322-
coro = AsyncMock()()
2326+
2327+
async def _noop():
2328+
pass
2329+
2330+
coro = _noop()
23232331

23242332
with patch.object(type(app), "screen", new_callable=PropertyMock) as prop:
23252333
prop.return_value = mock_dashboard
23262334
app._run_command(coro, "test...", "test failed")
23272335

23282336
assert app._write_in_progress is True
23292337
mock_dashboard.log_message.assert_any_call("test...")
2338+
coro.close()
2339+
for w in app._captured_workers:
2340+
w.close()
23302341

23312342
async def test_worker_clears_flag_on_success(self, mock_client, mock_dashboard):
23322343
app = _make_app(mock_client, mock_dashboard)
2333-
coro = AsyncMock()()
2344+
2345+
async def _noop():
2346+
pass
2347+
2348+
coro = _noop()
23342349

23352350
with patch.object(type(app), "screen", new_callable=PropertyMock) as prop:
23362351
prop.return_value = mock_dashboard

tests/test_tui_screens.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ async def test_credential_submit_triggers_worker(self):
12461246
app.screen.query_one("#sign-in-btn", Button).press()
12471247
await pilot.pause()
12481248
mock_worker.assert_called_once()
1249+
mock_worker.call_args[0][0].close()
12491250

12501251
async def test_credential_login_success_dismisses(self):
12511252
"""Successful credential login dismisses with the redirect URL."""
@@ -1311,10 +1312,11 @@ async def test_password_submitted_triggers_on_submit(self):
13111312
async with app.run_test(size=(80, 25)) as pilot:
13121313
app.screen.query_one("#email-input", Input).value = "user@test.com"
13131314
app.screen.query_one("#password-input", Input).value = "secret"
1314-
with patch.object(app.screen, "run_worker"):
1315+
with patch.object(app.screen, "run_worker") as mock_worker:
13151316
pw_input = app.screen.query_one("#password-input", Input)
13161317
await pw_input.action_submit()
13171318
await pilot.pause()
1319+
mock_worker.call_args[0][0].close()
13181320

13191321
async def test_button_pressed_non_sign_in_ignored(self):
13201322
"""Button press on non sign-in button should be ignored."""

0 commit comments

Comments
 (0)