Skip to content

Commit

Permalink
fail on inconsistent lock file (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored Jan 5, 2025
1 parent db7edd9 commit 7c12225
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ def handle(self) -> int:

if not locker.is_fresh():
self.line_error(
"<warning>"
"Warning: poetry.lock is not consistent with pyproject.toml. "
"You may be getting improper dependencies. "
"Run `poetry lock [--no-update]` to fix it."
"</warning>"
"<error>"
"pyproject.toml changed significantly since poetry.lock was last"
" generated. Run `poetry lock` to fix the lock file."
"</error>"
)
return 1

if self.option("extras") and self.option("all-extras"):
self.line_error(
Expand Down
13 changes: 13 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7c12225

Please sign in to comment.