diff --git a/freqtrade/configuration.py b/freqtrade/configuration.py index 2a9e8fbd8..0b484c57a 100644 --- a/freqtrade/configuration.py +++ b/freqtrade/configuration.py @@ -61,11 +61,9 @@ class Configuration(object): with open(path) as file: conf = json.load(file) except FileNotFoundError: - logger.critical( - 'Config file "%s" not found. Please create your config file', - path - ) - exit(0) + raise OperationalException( + 'Config file "{}" not found!' + ' Please create a config file or check whether it exists.'.format(path)) if 'internals' not in conf: conf['internals'] = {} diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 5e768518b..88c06c111 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -277,7 +277,7 @@ def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict: 'bid': float(data['bid']), 'ask': float(data['ask']), } - except KeyError as e: + except KeyError: logger.debug("Could not cache ticker data for %s", pair) return data except (ccxt.NetworkError, ccxt.ExchangeError) as e: diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index 2f633c021..caaddbf25 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -85,7 +85,7 @@ def test_load_config_max_open_trades_zero(default_conf, mocker, caplog) -> None: assert log_has('Validating configuration ...', caplog.record_tuples) -def test_load_config_file_exception(mocker, caplog) -> None: +def test_load_config_file_exception(mocker) -> None: """ Test Configuration._load_config_file() method """ @@ -95,12 +95,8 @@ def test_load_config_file_exception(mocker, caplog) -> None: ) configuration = Configuration(Namespace()) - with pytest.raises(SystemExit): + with pytest.raises(OperationalException, match=r'.*Config file "somefile" not found!*'): configuration._load_config_file('somefile') - assert log_has( - 'Config file "somefile" not found. Please create your config file', - caplog.record_tuples - ) def test_load_config(default_conf, mocker) -> None: diff --git a/scripts/plot_profit.py b/scripts/plot_profit.py index a5ac00169..803bf71de 100755 --- a/scripts/plot_profit.py +++ b/scripts/plot_profit.py @@ -93,7 +93,7 @@ def plot_profit(args: Namespace) -> None: 'Impossible to load the strategy. Please check the file "user_data/strategies/%s.py"', config.get('strategy') ) - exit(0) + exit(1) # Load the profits results try: @@ -104,7 +104,7 @@ def plot_profit(args: Namespace) -> None: logger.critical( 'File "backtest-result.json" not found. This script require backtesting ' 'results to run.\nPlease run a backtesting with the parameter --export.') - exit(0) + exit(1) # Take pairs from the cli otherwise switch to the pair in the config file if args.pair: