diff --git a/airflow/cli/commands/config_command.py b/airflow/cli/commands/config_command.py index f159723764093..82f1943d4cf84 100644 --- a/airflow/cli/commands/config_command.py +++ b/airflow/cli/commands/config_command.py @@ -24,6 +24,7 @@ from pygments.lexers.configs import IniLexer from airflow.configuration import conf +from airflow.exceptions import AirflowConfigException from airflow.utils.cli import should_use_colors from airflow.utils.code_utils import get_terminal_formatter from airflow.utils.providers_configuration_loader import providers_configuration_loaded @@ -58,8 +59,8 @@ def get_value(args): # providers are initialized. Theoretically Providers might add new sections and options # but also override defaults for existing options, so without loading all providers we # cannot be sure what is the final value of the option. - if not conf.has_option(args.section, args.option): - raise SystemExit(f"The option [{args.section}/{args.option}] is not found in config.") - - value = conf.get(args.section, args.option) - print(value) + try: + value = conf.get(args.section, args.option) + print(value) + except AirflowConfigException: + pass diff --git a/tests/cli/commands/test_config_command.py b/tests/cli/commands/test_config_command.py index 9a22e1c09f748..030303c28ec4d 100644 --- a/tests/cli/commands/test_config_command.py +++ b/tests/cli/commands/test_config_command.py @@ -20,8 +20,6 @@ from io import StringIO from unittest import mock -import pytest - from airflow.cli import cli_parser from airflow.cli.commands import config_command from tests.test_utils.config import conf_vars @@ -222,13 +220,8 @@ def test_should_not_raise_exception_when_section_for_config_with_value_defined_e config_command.get_value(self.parser.parse_args(["config", "get-value", "some_section", "value"])) - @mock.patch("airflow.cli.commands.config_command.conf") - def test_should_raise_exception_when_option_is_missing(self, mock_conf): - mock_conf.has_section.return_value = True - mock_conf.has_option.return_value = False - - with pytest.raises(SystemExit) as ctx: - config_command.get_value( - self.parser.parse_args(["config", "get-value", "missing-section", "dags_folder"]) - ) - assert "The option [missing-section/dags_folder] is not found in config." == str(ctx.value) + def test_should_raise_exception_when_option_is_missing(self, caplog): + config_command.get_value( + self.parser.parse_args(["config", "get-value", "missing-section", "dags_folder"]) + ) + assert "section/key [missing-section/dags_folder] not found in config" in caplog.text diff --git a/tests/cli/commands/test_plugins_command.py b/tests/cli/commands/test_plugins_command.py index 8ffe521b888ef..5a1c8d64e10df 100644 --- a/tests/cli/commands/test_plugins_command.py +++ b/tests/cli/commands/test_plugins_command.py @@ -21,6 +21,8 @@ from contextlib import redirect_stdout from io import StringIO +import pytest + from airflow.cli import cli_parser from airflow.cli.commands import plugins_command from airflow.hooks.base import BaseHook @@ -29,6 +31,8 @@ from tests.plugins.test_plugin import AirflowTestPlugin as ComplexAirflowPlugin from tests.test_utils.mock_plugins import mock_plugin_manager +pytestmark = pytest.mark.db_test + class PluginHook(BaseHook): pass diff --git a/tests/cli/test_cli_parser.py b/tests/cli/test_cli_parser.py index 9fd5bf48b0ef7..2244b6dbd5860 100644 --- a/tests/cli/test_cli_parser.py +++ b/tests/cli/test_cli_parser.py @@ -45,6 +45,8 @@ from airflow.providers.celery.executors.celery_executor import CeleryExecutor from tests.test_utils.config import conf_vars +pytestmark = pytest.mark.db_test + # Can not be `--snake_case` or contain uppercase letter ILLEGAL_LONG_OPTION_PATTERN = re.compile("^--[a-z]+_[a-z]+|^--.*[A-Z].*") # Only can be `-[a-z]` or `-[A-Z]`