From a6d003ae5d0e9329ceb9fcdc3281f6569d6a30d2 Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Wed, 26 May 2021 12:38:50 -0400 Subject: [PATCH 1/2] 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 --- poetry/console/commands/export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 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. " From db9694849be219d57601b703b0b8e7c25dd76a91 Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Fri, 4 Jun 2021 10:29:28 -0400 Subject: [PATCH 2/2] Looks at stderr for export tests --- tests/console/commands/test_export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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):