From 4ea5fcc6613b229345e576098dc0dc6a133a4029 Mon Sep 17 00:00:00 2001 From: gcarq Date: Sat, 23 Jun 2018 14:42:22 +0200 Subject: [PATCH] resolver: don't fail if user_data can't be found --- freqtrade/strategy/resolver.py | 11 +++++++---- freqtrade/tests/strategy/test_strategy.py | 13 ++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/freqtrade/strategy/resolver.py b/freqtrade/strategy/resolver.py index 73abb7cee..0dcd3fc6a 100644 --- a/freqtrade/strategy/resolver.py +++ b/freqtrade/strategy/resolver.py @@ -81,10 +81,13 @@ class StrategyResolver(object): abs_paths.insert(0, extra_dir) for path in abs_paths: - strategy = self._search_strategy(path, strategy_name) - if strategy: - logger.info('Using resolved strategy %s from \'%s\'', strategy_name, path) - return import_strategy(strategy) + try: + strategy = self._search_strategy(path, strategy_name) + if strategy: + logger.info('Using resolved strategy %s from \'%s\'', strategy_name, path) + return import_strategy(strategy) + except FileNotFoundError: + logger.warning('Path "%s" does not exist', path) raise ImportError( "Impossible to load Strategy '{}'. This class does not exist" diff --git a/freqtrade/tests/strategy/test_strategy.py b/freqtrade/tests/strategy/test_strategy.py index 13eac3261..1e082c380 100644 --- a/freqtrade/tests/strategy/test_strategy.py +++ b/freqtrade/tests/strategy/test_strategy.py @@ -50,13 +50,16 @@ def test_load_strategy(result): assert 'adx' in resolver.strategy.populate_indicators(result) -def test_load_strategy_custom_directory(result): +def test_load_strategy_invalid_directory(result, caplog): resolver = StrategyResolver() extra_dir = os.path.join('some', 'path') - with pytest.raises( - FileNotFoundError, - match=r".*No such file or directory: '{}'".format(extra_dir)): - resolver._load_strategy('TestStrategy', extra_dir) + resolver._load_strategy('TestStrategy', extra_dir) + + assert ( + 'freqtrade.strategy.resolver', + logging.WARNING, + 'Path "{}" does not exist'.format(extra_dir), + ) in caplog.record_tuples assert hasattr(resolver.strategy, 'populate_indicators') assert 'adx' in resolver.strategy.populate_indicators(result)