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

fix(show): handle missing lockfile #5242

Merged
merged 1 commit into from
Feb 28, 2022
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
7 changes: 7 additions & 0 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def handle(self) -> Optional[int]:
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