Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail on inconsistent lock file #310

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading