Skip to content

Commit 24a5e59

Browse files
committed
Fix installer cancel test: mock detect_strategy
The test was flaky because detect_strategy() could return a strategy that doesn't support auto-install (depending on environment), causing the code to return early without ever calling subprocess.Popen.
1 parent f7bdbb5 commit 24a5e59

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/test_installer_cancel.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import subprocess
44
import threading
5-
from unittest.mock import patch
5+
from unittest.mock import MagicMock, patch
66

77
from sqlit.db.exceptions import MissingDriverError
88
from sqlit.services.installer import Installer
@@ -46,7 +46,14 @@ def fake_popen(*args, **kwargs): # noqa: ANN001,ARG001
4646
proc_holder["proc"] = proc
4747
return proc
4848

49-
with patch("sqlit.services.installer.subprocess.Popen", new=fake_popen):
49+
fake_strategy = MagicMock()
50+
fake_strategy.can_auto_install = True
51+
fake_strategy.auto_install_command = ["pip", "install", "psycopg2-binary"]
52+
53+
with (
54+
patch("sqlit.services.installer.subprocess.Popen", new=fake_popen),
55+
patch("sqlit.services.installer.detect_strategy", return_value=fake_strategy),
56+
):
5057
result_holder: dict[str, tuple[bool, str, MissingDriverError]] = {}
5158

5259
def run():

0 commit comments

Comments
 (0)