Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No traceback on missing configuration with towncrier check #501

Merged
merged 13 commits into from
May 8, 2023
2 changes: 1 addition & 1 deletion src/towncrier/_settings/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def load_config_from_options(
config = load_config_from_file(os.path.dirname(config_path), config_path)

if config is None:
raise ConfigError(f"No configuration file found.\nLooked in: {base_directory}")
sys.exit(f"No configuration file found.\nLooked in: {base_directory}")

return base_directory, config

Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/501.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't raise an exception with ``towncrier check`` on missing configuration.
chrysle marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions src/towncrier/test/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

from textwrap import dedent

from click.testing import CliRunner
from twisted.trial.unittest import TestCase

from .._settings import ConfigError, load_config
from .._shell import cli


class TomlSettingsTests(TestCase):
Expand Down Expand Up @@ -153,6 +155,21 @@ def test_towncrier_toml_preferred(self):
config = load_config(temp)
self.assertEqual(config.package, "a")

def test_load_no_config(self):
"""
Check that no exception is raised if no config is found in the base directory.
chrysle marked this conversation as resolved.
Show resolved Hide resolved
"""
temp = self.mktemp()
os.makedirs(temp)
hynek marked this conversation as resolved.
Show resolved Hide resolved

runner = CliRunner()
chrysle marked this conversation as resolved.
Show resolved Hide resolved
result = runner.invoke(cli, ["--dir", temp])
self.assertEqual(
result.output,
f"No configuration file found.\nLooked in: {os.path.abspath(temp)}\n",
)
self.assertEqual(result.exit_code, 1)

def test_missing_template(self):
"""
Towncrier will raise an exception saying when it can't find a template.
Expand Down