Skip to content

Commit

Permalink
fix(show): handle missing lockfile (#5242)
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent authored Feb 28, 2022
1 parent da9680b commit e403ff4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def handle(self) -> int | None:
if self.option("default"):
only_groups.append("default")

if not self.poetry.locker.is_locked():
self.line_error(
"<error>Error: poetry.lock not found. Run `poetry lock` to create"
" it.</error>"
)
return 1

locked_repo = self.poetry.locker.locked_repository(True)

if only_groups:
Expand Down
10 changes: 10 additions & 0 deletions tests/console/commands/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,3 +1587,13 @@ def test_show_required_by_deps(
""".splitlines()
actual = [line.rstrip() for line in tester.io.fetch_output().splitlines()]
assert actual == expected


def test_show_errors_without_lock_file(tester: "CommandTester", poetry: "Poetry"):
assert not poetry.locker.lock.exists()

tester.execute()

expected = "Error: poetry.lock not found. Run `poetry lock` to create it.\n"
assert tester.io.fetch_error() == expected
assert tester.status_code == 1

0 comments on commit e403ff4

Please sign in to comment.