Skip to content

Commit

Permalink
upgrade extremely useful (and easy to miss) warning to an error
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Dec 4, 2023
1 parent 0578ed8 commit ebddf37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ def _do_install(self) -> int:
locked_repository = self._locker.locked_repository()

if not self._locker.is_fresh():
self._io.write_error_line(
"<warning>"
"Warning: poetry.lock is not consistent with pyproject.toml. "
raise ValueError(
"<error>"
"Error: poetry.lock is not consistent with pyproject.toml. "
"You may be getting improper dependencies. "
"Run `poetry lock [--no-update]` to fix it."
"</warning>"
"</error>"
)

locker_extras = {
Expand Down
22 changes: 21 additions & 1 deletion tests/installation/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json

import re
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
Expand Down Expand Up @@ -97,6 +98,7 @@ def __init__(self, lock_path: Path) -> None:
self._lock = lock_path / "poetry.lock"
self._written_data = None
self._locked = False
self._fresh = True
self._lock_data = None
self._content_hash = self._get_content_hash()

Expand All @@ -121,8 +123,13 @@ def mock_lock_data(self, data: dict[str, Any]) -> None:
def is_locked(self) -> bool:
return self._locked

def fresh(self, is_fresh: bool = True) -> Locker:
self._fresh = is_fresh

return self

def is_fresh(self) -> bool:
return True
return self._fresh

def _get_content_hash(self) -> str:
return "123456789"
Expand Down Expand Up @@ -208,6 +215,19 @@ def test_run_no_dependencies(installer: Installer, locker: Locker) -> None:
assert locker.written_data == expected


def test_not_fresh_lock(installer: Installer, locker: Locker) -> None:
locker.locked().fresh(False)
with pytest.raises(
ValueError,
match=re.escape(
"<error>Error: poetry.lock is not consistent with pyproject.toml. You may"
" be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
" it.</error>"
),
):
installer.run()


def test_run_with_dependencies(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage
) -> None:
Expand Down

0 comments on commit ebddf37

Please sign in to comment.