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 13, 2023
1 parent f310a59 commit 81133c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,9 @@ 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. "
"You may be getting improper dependencies. "
raise ValueError(
"poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it."
"</warning>"
)

locker_extras = {
Expand Down
21 changes: 20 additions & 1 deletion tests/installation/test_installer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import re

from pathlib import Path
from typing import TYPE_CHECKING
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,18 @@ 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(
"poetry.lock is not consistent with pyproject.toml."
" Run `poetry lock [--no-update]` to fix it."
),
):
installer.run()


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

0 comments on commit 81133c2

Please sign in to comment.