Skip to content

Commit

Permalink
Make unit test for missing git executable more generic (ansible#78173)
Browse files Browse the repository at this point in the history
* Make unit test for missing git executable more generic

* use MagicMock side_effect to raise exception instead
  • Loading branch information
s-hertel committed Jun 30, 2022
1 parent 6bcb494 commit 1562672
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/units/galaxy/test_collection_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,14 @@ def test_concrete_artifact_manager_scm_no_executable(monkeypatch):
monkeypatch.setattr(collection.concrete_artifact_manager.subprocess, 'check_call', mock_subprocess_check_call)
mock_mkdtemp = MagicMock(return_value='')
monkeypatch.setattr(collection.concrete_artifact_manager, 'mkdtemp', mock_mkdtemp)
mock_get_bin_path = MagicMock(side_effect=[ValueError('Failed to find required executable')])
monkeypatch.setattr(collection.concrete_artifact_manager, 'get_bin_path', mock_get_bin_path)

error = re.escape(
"Could not find git executable to extract the collection from the Git repository `https://github.com/org/repo`"
)
with mock.patch.dict(os.environ, {"PATH": ""}):
with pytest.raises(AnsibleError, match=error):
collection.concrete_artifact_manager._extract_collection_from_git(url, version, b'path')
with pytest.raises(AnsibleError, match=error):
collection.concrete_artifact_manager._extract_collection_from_git(url, version, b'path')


@pytest.mark.parametrize(
Expand Down

0 comments on commit 1562672

Please sign in to comment.