Skip to content

Commit d0fbc3f

Browse files
committed
test(fix[codecommit]) Mock subprocess in _get_importer CodeCommit tests
why: test_get_importer creates real CodeCommitImporter instances which call _check_aws_cli() running subprocess.run(["aws", "--version"]). Tests fail in CI environments without the AWS CLI installed. what: - Add monkeypatch for subprocess.run when service is codecommit/cc/aws - Add subprocess import to test file
1 parent a1004f7 commit d0fbc3f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/cli/test_import_repos.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import logging
77
import pathlib
8+
import subprocess
89
import sys
910
import typing as t
1011

@@ -227,8 +228,18 @@ def test_get_importer(
227228
profile: str | None,
228229
expected_type_name: str,
229230
expected_error: str | None,
231+
monkeypatch: MonkeyPatch,
230232
) -> None:
231233
"""Test _get_importer creates the correct importer type."""
234+
# Mock subprocess.run for CodeCommit tests (aws --version check)
235+
if service in ("codecommit", "cc", "aws"):
236+
monkeypatch.setattr(
237+
"subprocess.run",
238+
lambda cmd, **kwargs: subprocess.CompletedProcess(
239+
cmd, 0, stdout="aws-cli/2.x", stderr=""
240+
),
241+
)
242+
232243
if expected_error:
233244
with pytest.raises(ValueError, match=expected_error):
234245
_get_importer(

0 commit comments

Comments
 (0)