Skip to content

Commit 0fc4f34

Browse files
committed
Enhance test for 'init' command to skip config creation when it exists
1 parent 40a115b commit 0fc4f34

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/test_cli.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,27 @@ def mock_get_config_path():
108108
config = json.load(f)
109109
assert config == utils.DEFAULT_CONFIG
110110

111-
def test_init_skips_when_config_exists(self, cli_env, capfd):
111+
def test_init_skips_when_config_exists(self, cli_env, capfd, monkeypatch):
112112
"""Test that 'init' command skips creation when config already exists."""
113+
config_path = Path(cli_env["config_path"])
114+
115+
# Mock get_config_path to return our test config
116+
def mock_get_config_path():
117+
return config_path
118+
monkeypatch.setattr(utils, "get_config_path", mock_get_config_path)
119+
120+
# Mock Path.exists to return True
121+
def mock_exists(self):
122+
return True
123+
monkeypatch.setattr(Path, "exists", mock_exists)
124+
113125
# Execute init command
114126
args = mock.Mock()
115127
commands.init_command(args)
116128

117129
# Verify output indicates config already exists
118130
out, _ = capfd.readouterr()
119-
assert "already exists" in out
131+
assert f"already exists" in out
120132

121133

122134
class TestCliAdd:

0 commit comments

Comments
 (0)