Skip to content

Commit

Permalink
poetry config: handle missing poetry section
Browse files Browse the repository at this point in the history
Resolves: #3084

Co-authored-by: Etty <beltrami.ester@gmail.com>
  • Loading branch information
finswimmer and estyxx authored Oct 12, 2020
1 parent b10a397 commit 655c5d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"):
Expand Down
11 changes: 11 additions & 0 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from poetry.config.config_source import ConfigSource
from poetry.core.pyproject import PyProjectException
from poetry.factory import Factory


Expand All @@ -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")

Expand Down

0 comments on commit 655c5d3

Please sign in to comment.