diff --git a/src/poetry/console/commands/show.py b/src/poetry/console/commands/show.py index e9fcefec3ce..5f0e4c12a78 100644 --- a/src/poetry/console/commands/show.py +++ b/src/poetry/console/commands/show.py @@ -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: poetry.lock not found. Run `poetry lock` to create" + " it." + ) + return 1 + locked_repo = self.poetry.locker.locked_repository(True) if only_groups: diff --git a/tests/console/commands/test_show.py b/tests/console/commands/test_show.py index d5604b86cb1..06c13cd9427 100644 --- a/tests/console/commands/test_show.py +++ b/tests/console/commands/test_show.py @@ -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