From b3c499bfe71921f9a21eab58f4f09495ed7971d4 Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Fri, 3 Sep 2021 15:20:58 -0400 Subject: [PATCH] Emit export errors to stderr to prevent invalid output (#4110) * Emit export errors to stderr to prevent invalid output An error in export could emit error messages to stdout, causing the requirements.txt output to stdout to be invalid. Fixes #4109 * Looks at stderr for export tests --- poetry/console/commands/export.py | 4 ++-- tests/console/commands/test_export.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/poetry/console/commands/export.py b/poetry/console/commands/export.py index a58d96f50fe..accdc199460 100644 --- a/poetry/console/commands/export.py +++ b/poetry/console/commands/export.py @@ -41,7 +41,7 @@ def handle(self) -> None: locker = self.poetry.locker if not locker.is_locked(): - self.line("The lock file does not exist. Locking.") + self.line_error("The lock file does not exist. Locking.") options = [] if self.io.is_debug(): options.append(("-vvv", None)) @@ -53,7 +53,7 @@ def handle(self) -> None: self.call("lock", " ".join(options)) if not locker.is_fresh(): - self.line( + self.line_error( "" "Warning: The lock file is not up to date with " "the latest changes in pyproject.toml. " diff --git a/tests/console/commands/test_export.py b/tests/console/commands/test_export.py index f5b9fba4a7d..0c4efc2e45e 100644 --- a/tests/console/commands/test_export.py +++ b/tests/console/commands/test_export.py @@ -77,12 +77,12 @@ def _export_requirements(tester, poetry): def test_export_exports_requirements_txt_file_locks_if_no_lock_file(tester, poetry): assert not poetry.locker.lock.exists() _export_requirements(tester, poetry) - assert "The lock file does not exist. Locking." in tester.io.fetch_output() + assert "The lock file does not exist. Locking." in tester.io.fetch_error() def test_export_exports_requirements_txt_uses_lock_file(tester, poetry, do_lock): _export_requirements(tester, poetry) - assert "The lock file does not exist. Locking." not in tester.io.fetch_output() + assert "The lock file does not exist. Locking." not in tester.io.fetch_error() def test_export_fails_on_invalid_format(tester, do_lock):