Skip to content

Commit c320955

Browse files
authored
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
1 parent e180aab commit c320955

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

poetry/console/commands/export.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def handle(self) -> None:
4141

4242
locker = self.poetry.locker
4343
if not locker.is_locked():
44-
self.line("<comment>The lock file does not exist. Locking.</comment>")
44+
self.line_error("<comment>The lock file does not exist. Locking.</comment>")
4545
options = []
4646
if self.io.is_debug():
4747
options.append(("-vvv", None))
@@ -53,7 +53,7 @@ def handle(self) -> None:
5353
self.call("lock", " ".join(options))
5454

5555
if not locker.is_fresh():
56-
self.line(
56+
self.line_error(
5757
"<warning>"
5858
"Warning: The lock file is not up to date with "
5959
"the latest changes in pyproject.toml. "

tests/console/commands/test_export.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ def _export_requirements(tester, poetry):
7777
def test_export_exports_requirements_txt_file_locks_if_no_lock_file(tester, poetry):
7878
assert not poetry.locker.lock.exists()
7979
_export_requirements(tester, poetry)
80-
assert "The lock file does not exist. Locking." in tester.io.fetch_output()
80+
assert "The lock file does not exist. Locking." in tester.io.fetch_error()
8181

8282

8383
def test_export_exports_requirements_txt_uses_lock_file(tester, poetry, do_lock):
8484
_export_requirements(tester, poetry)
85-
assert "The lock file does not exist. Locking." not in tester.io.fetch_output()
85+
assert "The lock file does not exist. Locking." not in tester.io.fetch_error()
8686

8787

8888
def test_export_fails_on_invalid_format(tester, do_lock):

0 commit comments

Comments
 (0)