diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index bb42bcff9..1ce7b0af0 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -2,6 +2,7 @@ import json import logging from datetime import datetime +from typing import Dict, Optional from functools import reduce from unittest.mock import MagicMock @@ -34,7 +35,8 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot: :param config: Config to pass to the bot :return: None """ - mocker.patch('freqtrade.fiat_convert.Market', {'price_usd': 12345.0}) + # mocker.patch('freqtrade.fiat_convert.Market', {'price_usd': 12345.0}) + patch_coinmarketcap(mocker, {'price_usd': 12345.0}) mocker.patch('freqtrade.freqtradebot.Analyze', MagicMock()) mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.persistence.init', MagicMock()) @@ -46,6 +48,25 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot: return FreqtradeBot(config, create_engine('sqlite://')) +def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> None: + """ + Mocker to coinmarketcap to speed up tests + :param mocker: mocker to patch coinmarketcap class + :return: None + """ + mock = MagicMock() + + if value: + mock.ticker = {'price_usd': 12345.0} + mock.listings = {'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC', + 'website_slug': 'bitcoin'}, + {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', + 'website_slug': 'ethereum'} + ]} + + mocker.patch('freqtrade.fiat_convert.Market', mock) + + @pytest.fixture(scope="function") def default_conf(): """ Returns validated configuration suitable for most tests """ diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py index ead796aca..d9de2c3dc 100644 --- a/freqtrade/tests/test_freqtradebot.py +++ b/freqtrade/tests/test_freqtradebot.py @@ -8,7 +8,6 @@ import logging import re import time from copy import deepcopy -from typing import Dict, Optional from unittest.mock import MagicMock import arrow @@ -20,7 +19,7 @@ from freqtrade import DependencyException, OperationalException, TemporaryError from freqtrade.freqtradebot import FreqtradeBot from freqtrade.persistence import Trade from freqtrade.state import State -from freqtrade.tests.conftest import log_has +from freqtrade.tests.conftest import log_has, patch_coinmarketcap # Functions for recurrent object patching @@ -64,20 +63,6 @@ def patch_RPCManager(mocker) -> MagicMock: return rpc_mock -def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> None: - """ - Mocker to coinmarketcap to speed up tests - :param mocker: mocker to patch coinmarketcap class - :return: None - """ - mock = MagicMock() - - if value: - mock.ticker = {'price_usd': 12345.0} - - mocker.patch('freqtrade.fiat_convert.Market', mock) - - # Unit tests def test_freqtradebot_object() -> None: """