diff --git a/freqtrade/resolvers/iresolver.py b/freqtrade/resolvers/iresolver.py index 6807b757d..b437166e7 100644 --- a/freqtrade/resolvers/iresolver.py +++ b/freqtrade/resolvers/iresolver.py @@ -148,6 +148,9 @@ class IResolver: logger.debug("Ignoring broken symlink %s", entry) continue module_path = entry.resolve() + if entry.read_text().find(f"class {object_name}(") == -1: + logger.debug(f"Skipping {module_path} as it does not contain class {object_name}.") + continue if obj := next(cls._get_valid_object(module_path, object_name), None): obj[0].__file__ = str(entry) diff --git a/tests/strategy/test_strategy_loading.py b/tests/strategy/test_strategy_loading.py index 923f3635b..80ff025fb 100644 --- a/tests/strategy/test_strategy_loading.py +++ b/tests/strategy/test_strategy_loading.py @@ -96,6 +96,16 @@ def test_load_strategy_invalid_directory(caplog, default_conf, tmp_path): assert log_has_re(r"Path .*" + r"some.*path.*" + r".* does not exist", caplog) +def test_load_strategy_skip_other_files(caplog, default_conf, tmp_path): + default_conf["user_data_dir"] = tmp_path + caplog.set_level(logging.DEBUG) + + s = StrategyResolver._load_strategy("StrategyTestV3", config=default_conf) + assert isinstance(s, IStrategy) + + assert log_has_re(r"Skipping .* as it does not contain class StrategyTestV3\.", caplog) + + def test_load_not_found_strategy(default_conf, tmp_path): default_conf["user_data_dir"] = tmp_path default_conf["strategy"] = "NotFoundStrategy"