diff --git a/bigchaindb/config_utils.py b/bigchaindb/config_utils.py index 5a72a7d6..57d10f74 100644 --- a/bigchaindb/config_utils.py +++ b/bigchaindb/config_utils.py @@ -238,7 +238,10 @@ def autoconfigure(filename=None, config=None, force=False): try: newconfig = update(newconfig, file_config(filename=filename)) except FileNotFoundError as e: - logger.warning('Cannot find config file `%s`.' % e.filename) + if filename: + raise + else: + logger.info('Cannot find config file `%s`.' % e.filename) # override configuration with env variables newconfig = env_config(newconfig) diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 37079ddd..b50a2a67 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -88,11 +88,12 @@ def test_bigchain_show_config(capsys): assert output_config == config +@pytest.mark.usefixtures('ignore_local_config_file') def test_bigchain_export_my_pubkey_when_pubkey_set(capsys, monkeypatch): from bigchaindb import config from bigchaindb.commands.bigchaindb import run_export_my_pubkey - args = Namespace(config='dummy') + args = Namespace(config=None) # so in run_export_my_pubkey(args) below, # filename=args.config='dummy' is passed to autoconfigure(). # We just assume autoconfigure() works and sets @@ -107,11 +108,12 @@ def test_bigchain_export_my_pubkey_when_pubkey_set(capsys, monkeypatch): assert 'Charlie_Bucket' in lines +@pytest.mark.usefixtures('ignore_local_config_file') def test_bigchain_export_my_pubkey_when_pubkey_not_set(monkeypatch): from bigchaindb import config from bigchaindb.commands.bigchaindb import run_export_my_pubkey - args = Namespace(config='dummy') + args = Namespace(config=None) monkeypatch.setitem(config['keypair'], 'public', None) # assert that run_export_my_pubkey(args) raises SystemExit: with pytest.raises(SystemExit) as exc_info: diff --git a/tests/conftest.py b/tests/conftest.py index 26beac11..d60b4511 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -199,7 +199,7 @@ def _genesis(_bdb, genesis_block): @pytest.fixture def ignore_local_config_file(monkeypatch): def mock_file_config(filename=None): - raise FileNotFoundError() + return {} monkeypatch.setattr('bigchaindb.config_utils.file_config', mock_file_config) diff --git a/tests/test_config_utils.py b/tests/test_config_utils.py index bb445d83..88c3431e 100644 --- a/tests/test_config_utils.py +++ b/tests/test_config_utils.py @@ -257,6 +257,18 @@ def test_autoconfigure_env_precedence(monkeypatch): assert bigchaindb.config['server']['bind'] == 'localhost:9985' +def test_autoconfigure_explicit_file(monkeypatch): + from bigchaindb import config_utils + + def file_config(*args, **kwargs): + raise FileNotFoundError() + + monkeypatch.setattr('bigchaindb.config_utils.file_config', file_config) + + with pytest.raises(FileNotFoundError): + config_utils.autoconfigure(filename='autoexec.bat') + + def test_update_config(monkeypatch): import bigchaindb from bigchaindb import config_utils