diff --git a/src/poetry/console/commands/check.py b/src/poetry/console/commands/check.py index 30812883523..12bfc09343f 100644 --- a/src/poetry/console/commands/check.py +++ b/src/poetry/console/commands/check.py @@ -1,7 +1,5 @@ from __future__ import annotations -from pathlib import Path - from poetry.console.commands.command import Command @@ -61,7 +59,7 @@ def handle(self) -> int: from poetry.factory import Factory # Load poetry config and display errors, if any - poetry_file = Factory.locate(Path.cwd()) + poetry_file = self.poetry.file.path config = PyProjectTOML(poetry_file).poetry_config check_result = Factory.validate(config, strict=True) diff --git a/tests/console/commands/test_check.py b/tests/console/commands/test_check.py index 1c21a80f3e5..fcdfa5d9a19 100644 --- a/tests/console/commands/test_check.py +++ b/tests/console/commands/test_check.py @@ -29,12 +29,17 @@ def test_check_valid(tester: CommandTester): def test_check_invalid(mocker: MockerFixture, tester: CommandTester): + from poetry.core.toml import TOMLFile + mocker.patch( - "poetry.factory.Factory.locate", - return_value=Path(__file__).parent.parent.parent - / "fixtures" - / "invalid_pyproject" - / "pyproject.toml", + "poetry.poetry.Poetry.file", + return_value=TOMLFile( + Path(__file__).parent.parent.parent + / "fixtures" + / "invalid_pyproject" + / "pyproject.toml" + ), + new_callable=mocker.PropertyMock, ) tester.execute()