@@ -123,8 +123,11 @@ def test_install_tool_success():
123123 """Test _install_tool successful installation."""
124124 mock_path = "/usr/bin/clang-format"
125125
126+ def patched_run (* args , ** kwargs ):
127+ return subprocess .CompletedProcess (args , returncode = 0 )
128+
126129 with (
127- patch ("subprocess.run" ) as mock_run ,
130+ patch ("subprocess.run" , side_effect = patched_run ) as mock_run ,
128131 patch ("shutil.which" , return_value = mock_path ),
129132 ):
130133 result = _install_tool ("clang-format" , "20.1.7" )
@@ -133,18 +136,20 @@ def test_install_tool_success():
133136 mock_run .assert_called_once_with (
134137 [sys .executable , "-m" , "pip" , "install" , "clang-format==20.1.7" ],
135138 capture_output = True ,
136- check = True ,
137139 )
138140
139141
140142@pytest .mark .benchmark
141143def test_install_tool_failure ():
142144 """Test _install_tool when pip install fails."""
145+
146+ def patched_run (* args , ** kwargs ):
147+ return subprocess .CompletedProcess (
148+ args , returncode = 1 , stderr = b"Error" , stdout = b"Installation failed"
149+ )
150+
143151 with (
144- patch (
145- "subprocess.run" ,
146- side_effect = subprocess .CalledProcessError (1 , ["pip" ]),
147- ),
152+ patch ("subprocess.run" , side_effect = patched_run ),
148153 patch ("cpp_linter_hooks.util.LOG" ),
149154 ):
150155 result = _install_tool ("clang-format" , "20.1.7" )
0 commit comments