Skip to content

Commit 115bf36

Browse files
fix: Fix integration test mocking for consistent behavior
- Changed test_auth_failure_workflow to mock subprocess.run directly - Updated test_bedrock_api_error_workflow to use single mock with conditional logic - Avoids issues with patching imported functions across Python versions - All tests now pass consistently 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0f24bce commit 115bf36

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

tests/test_integration.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ def setup_method(self):
217217
"""Set up test fixtures."""
218218
self.runner = CliRunner(env={"NO_COLOR": "1"})
219219

220-
@patch("claude_setup.cli.check_aws_auth")
220+
@patch("claude_setup.auth_checker.subprocess.run")
221221
@pytest.mark.skipif(
222222
sys.platform == "win32", reason="Temporary directory cleanup issues on Windows"
223223
)
224-
def test_auth_failure_workflow(self, mock_auth):
224+
def test_auth_failure_workflow(self, mock_subprocess_run):
225225
"""Test workflow when AWS authentication fails."""
226-
# Arrange
227-
mock_auth.return_value = False
226+
# Arrange - make subprocess.run raise CalledProcessError to simulate auth failure
227+
import subprocess
228+
mock_subprocess_run.side_effect = subprocess.CalledProcessError(1, "aws")
228229

229230
original_dir = os.getcwd()
230231
with tempfile.TemporaryDirectory() as temp_dir:
@@ -247,21 +248,27 @@ def test_auth_failure_workflow(self, mock_auth):
247248
finally:
248249
os.chdir(original_dir)
249250

250-
@patch("claude_setup.aws_client.subprocess.run")
251-
@patch("claude_setup.cli.check_aws_auth")
251+
@patch("subprocess.run")
252252
@pytest.mark.skipif(
253253
sys.platform == "win32", reason="Temporary directory cleanup issues on Windows"
254254
)
255-
def test_bedrock_api_error_workflow(self, mock_auth, mock_subprocess):
255+
def test_bedrock_api_error_workflow(self, mock_subprocess_run):
256256
"""Test workflow when Bedrock API returns error."""
257257
# Arrange
258-
mock_auth.return_value = True
259-
# subprocess.run is called when listing models - should raise CalledProcessError
260258
from subprocess import CalledProcessError
261-
262-
mock_subprocess.side_effect = CalledProcessError(
263-
1, "aws bedrock", stderr="AccessDeniedException: Not authorized"
264-
)
259+
260+
def side_effect(*args, **kwargs):
261+
# Check if this is the auth check call
262+
if args[0] == ["aws", "sts", "get-caller-identity"]:
263+
# Make auth check pass
264+
return MagicMock(returncode=0)
265+
else:
266+
# Make bedrock API call fail
267+
raise CalledProcessError(
268+
1, "aws bedrock", stderr="AccessDeniedException: Not authorized"
269+
)
270+
271+
mock_subprocess_run.side_effect = side_effect
265272

266273
original_dir = os.getcwd()
267274
with tempfile.TemporaryDirectory() as temp_dir:

0 commit comments

Comments
 (0)