From af735bca2d6996cd6cb6d81774e5051e1178d2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sun, 5 Jan 2025 17:32:07 +0100 Subject: [PATCH] fail on inconsistent lock file --- src/poetry_plugin_export/command.py | 10 +++++----- tests/command/test_command_export.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/poetry_plugin_export/command.py b/src/poetry_plugin_export/command.py index 8db0d06..51db1e7 100644 --- a/src/poetry_plugin_export/command.py +++ b/src/poetry_plugin_export/command.py @@ -104,12 +104,12 @@ def handle(self) -> int: if not locker.is_fresh(): self.line_error( - "" - "Warning: poetry.lock is not consistent with pyproject.toml. " - "You may be getting improper dependencies. " - "Run `poetry lock [--no-update]` to fix it." - "" + "" + "pyproject.toml changed significantly since poetry.lock was last" + " generated. Run `poetry lock` to fix the lock file." + "" ) + return 1 if self.option("extras") and self.option("all-extras"): self.line_error( diff --git a/tests/command/test_command_export.py b/tests/command/test_command_export.py index b15ee2b..792265b 100644 --- a/tests/command/test_command_export.py +++ b/tests/command/test_command_export.py @@ -21,6 +21,7 @@ from cleo.testers.command_tester import CommandTester from poetry.poetry import Poetry from poetry.repositories import Repository + from pytest_mock import MockerFixture from tests.types import CommandTesterFactory from tests.types import ProjectFactory @@ -134,6 +135,18 @@ def test_export_fails_on_invalid_format(tester: CommandTester, do_lock: None) -> tester.execute("--format invalid") +def test_export_fails_if_lockfile_is_not_fresh( + tester: CommandTester, + poetry: Poetry, + tmp_path: Path, + do_lock: None, + mocker: MockerFixture, +) -> None: + mocker.patch.object(poetry.locker, "is_fresh", return_value=False) + assert tester.execute() == 1 + assert "pyproject.toml changed significantly" in tester.io.fetch_error() + + def test_export_prints_to_stdout_by_default( tester: CommandTester, do_lock: None ) -> None: