Skip to content

Commit 9d59b9b

Browse files
committed
upgrade extremely useful (and easy to miss) warning to an error
1 parent 05f39ef commit 9d59b9b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/poetry/installation/installer.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,9 @@ def _do_install(self) -> int:
245245
locked_repository = self._locker.locked_repository()
246246

247247
if not self._locker.is_fresh():
248-
self._io.write_error_line(
249-
"<warning>"
250-
"Warning: poetry.lock is not consistent with pyproject.toml. "
251-
"You may be getting improper dependencies. "
248+
raise ValueError(
249+
"poetry.lock is not consistent with pyproject.toml. "
252250
"Run `poetry lock [--no-update]` to fix it."
253-
"</warning>"
254251
)
255252

256253
locker_extras = {

tests/installation/test_installer.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import json
4+
import re
45

56
from pathlib import Path
67
from typing import TYPE_CHECKING
@@ -97,6 +98,7 @@ def __init__(self, lock_path: Path) -> None:
9798
self._lock = lock_path / "poetry.lock"
9899
self._written_data = None
99100
self._locked = False
101+
self._fresh = True
100102
self._lock_data = None
101103
self._content_hash = self._get_content_hash()
102104

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

126+
def fresh(self, is_fresh: bool = True) -> Locker:
127+
self._fresh = is_fresh
128+
129+
return self
130+
124131
def is_fresh(self) -> bool:
125-
return True
132+
return self._fresh
126133

127134
def _get_content_hash(self) -> str:
128135
return "123456789"
@@ -208,6 +215,18 @@ def test_run_no_dependencies(installer: Installer, locker: Locker) -> None:
208215
assert locker.written_data == expected
209216

210217

218+
def test_not_fresh_lock(installer: Installer, locker: Locker) -> None:
219+
locker.locked().fresh(False)
220+
with pytest.raises(
221+
ValueError,
222+
match=re.escape(
223+
"poetry.lock is not consistent with pyproject.toml. "
224+
"Run `poetry lock [--no-update]` to fix it."
225+
),
226+
):
227+
installer.run()
228+
229+
211230
def test_run_with_dependencies(
212231
installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage
213232
) -> None:

0 commit comments

Comments
 (0)