Skip to content

Commit

Permalink
Emit export errors to stderr to prevent invalid output (python-poetry…
Browse files Browse the repository at this point in the history
…#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 python-poetry#4109

* Looks at stderr for export tests
  • Loading branch information
colindean authored and 1nF0rmed committed Nov 15, 2021
1 parent 703e417 commit 1a37773
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions poetry/console/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle(self) -> None:

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

if not locker.is_fresh():
self.line(
self.line_error(
"<warning>"
"Warning: The lock file is not up to date with "
"the latest changes in pyproject.toml. "
Expand Down
4 changes: 2 additions & 2 deletions tests/console/commands/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1a37773

Please sign in to comment.