Skip to content

Commit 2c43453

Browse files
committed
fix(test): mock get_vcs correctly
Previously, the test suite relied on the test environment to be the same as that of a developer and hence implicitly providing a git boundary. This allowed for certain test cases using fixtures to fail when tests are run from the release sdist. This change mocks `get_vcs` to ensure that these cases pass as expected. Resolves: python-poetry/poetry#9967
1 parent 159a12a commit 2c43453

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from pytest import Config
2121
from pytest import Parser
22+
from pytest_mock import MockerFixture
2223

2324

2425
def pytest_addoption(parser: Parser) -> None:
@@ -109,3 +110,13 @@ def python(venv: Path) -> str:
109110
@pytest.fixture()
110111
def f() -> Factory:
111112
return Factory()
113+
114+
115+
@pytest.fixture(autouse=True)
116+
def with_mocked_get_vcs(mocker: MockerFixture) -> None:
117+
from poetry.core.vcs.git import Git
118+
119+
mocker.patch(
120+
"poetry.core.vcs.git.Git.run", return_value="This is a mocked Git.run() output."
121+
)
122+
mocker.patch("poetry.core.vcs.get_vcs", return_value=Git())

tests/vcs/test_vcs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def reset_git() -> Iterator[None]:
3333
_reset_executable()
3434

3535

36+
@pytest.fixture(autouse=True)
37+
def with_mocked_get_vcs() -> None:
38+
# disabled global mocking of get_vcs
39+
pass
40+
41+
3642
@pytest.mark.parametrize(
3743
"url, normalized",
3844
[

0 commit comments

Comments
 (0)