From 47fe3f96ade68dfd15dc6c21741d9f14ca7b1f1d Mon Sep 17 00:00:00 2001 From: Etty Date: Sat, 10 Oct 2020 16:13:32 +0100 Subject: [PATCH 1/2] Catch PyProjectException when pyproject.toml is empty (cherry picked from commit 2db820d509f5680cb1fb2309aa1275a58775d386) --- poetry/console/commands/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/poetry/console/commands/config.py b/poetry/console/commands/config.py index 551876912c2..70b6c7673f1 100644 --- a/poetry/console/commands/config.py +++ b/poetry/console/commands/config.py @@ -4,6 +4,7 @@ from cleo import argument from cleo import option +from poetry.core.pyproject import PyProjectException from poetry.core.toml.file import TOMLFile from poetry.factory import Factory @@ -80,7 +81,7 @@ def handle(self): local_config_file = TOMLFile(self.poetry.file.parent / "poetry.toml") if local_config_file.exists(): config.merge(local_config_file.read()) - except RuntimeError: + except (RuntimeError, PyProjectException): local_config_file = TOMLFile(Path.cwd() / "poetry.toml") if self.option("local"): From a379c9cb70f9fb1e0bdd73ef7d277b6de1f66f7e Mon Sep 17 00:00:00 2001 From: Etty Date: Sat, 10 Oct 2020 16:14:51 +0100 Subject: [PATCH 2/2] Add test (cherry picked from commit 3b3791d3cac8b7d583699ac28086c10dc850b370) --- tests/console/commands/test_config.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/console/commands/test_config.py b/tests/console/commands/test_config.py index 4bf102073d5..bb13a268e2f 100644 --- a/tests/console/commands/test_config.py +++ b/tests/console/commands/test_config.py @@ -4,6 +4,7 @@ import pytest from poetry.config.config_source import ConfigSource +from poetry.core.pyproject import PyProjectException from poetry.factory import Factory @@ -12,6 +13,16 @@ def tester(command_tester_factory): return command_tester_factory("config") +def test_show_config_with_local_config_file_empty(tester, mocker): + mocker.patch( + "poetry.factory.Factory.create_poetry", + side_effect=PyProjectException("[tool.poetry] section not found"), + ) + tester.execute() + + assert "" == tester.io.fetch_output() + + def test_list_displays_default_value_if_not_set(tester, config): tester.execute("--list")