diff --git a/tests/conftest.py b/tests/conftest.py index a007aeb7e..8a5ba6683 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -117,7 +117,7 @@ def patch_freqtradebot(mocker, config) -> None: """ mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) persistence.init(config['db_url']) - patch_exchange(mocker, None) + patch_exchange(mocker) mocker.patch('freqtrade.freqtradebot.RPCManager._init', MagicMock()) mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock()) diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 5ab7cdb47..694a2228e 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -1363,9 +1363,7 @@ def test_get_order(default_conf, mocker, exchange_name): @pytest.mark.parametrize("exchange_name", EXCHANGES) def test_name(default_conf, mocker, exchange_name): - mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={})) - default_conf['exchange']['name'] = exchange_name - exchange = Exchange(default_conf) + exchange = get_patched_exchange(mocker, default_conf, id=exchange_name) assert exchange.name == exchange_name.title() assert exchange.id == exchange_name diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index ff5869009..66468927f 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -28,9 +28,9 @@ def prec_satoshi(a, b) -> float: # Unit tests def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None: mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index cf741a7ea..a776ad5df 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -90,7 +90,7 @@ def test_cleanup(default_conf, mocker) -> None: def test_authorized_only(default_conf, mocker, caplog) -> None: - patch_exchange(mocker, None) + patch_exchange(mocker) chat = Chat(0, 0) update = Update(randint(1, 100)) @@ -108,7 +108,7 @@ def test_authorized_only(default_conf, mocker, caplog) -> None: def test_authorized_only_unauthorized(default_conf, mocker, caplog) -> None: - patch_exchange(mocker, None) + patch_exchange(mocker) chat = Chat(0xdeadbeef, 0) update = Update(randint(1, 100)) update.message = Message(randint(1, 100), 0, datetime.utcnow(), chat) @@ -728,13 +728,12 @@ def test_forcesell_handle(default_conf, update, ticker, fee, mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) rpc_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock()) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets), - validate_pairs=MagicMock(return_value={}) ) freqtradebot = FreqtradeBot(default_conf) @@ -781,13 +780,12 @@ def test_forcesell_down_handle(default_conf, update, ticker, fee, return_value=15000.0) rpc_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock()) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets), - validate_pairs=MagicMock(return_value={}) ) freqtradebot = FreqtradeBot(default_conf) @@ -843,7 +841,6 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, markets, mocker get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets), - validate_pairs=MagicMock(return_value={}) ) default_conf['max_open_trades'] = 4 freqtradebot = FreqtradeBot(default_conf) @@ -927,11 +924,10 @@ def test_forcebuy_handle(default_conf, update, markets, mocker) -> None: mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.telegram.Telegram._send_msg', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock()) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), markets=PropertyMock(markets), - validate_pairs=MagicMock(return_value={}) ) fbuy_mock = MagicMock(return_value=None) mocker.patch('freqtrade.rpc.RPC._rpc_forcebuy', fbuy_mock) @@ -967,11 +963,10 @@ def test_forcebuy_handle_exception(default_conf, update, markets, mocker) -> Non mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) rpc_mock = mocker.patch('freqtrade.rpc.telegram.Telegram._send_msg', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock()) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), markets=PropertyMock(markets), - validate_pairs=MagicMock(return_value={}) ) freqtradebot = FreqtradeBot(default_conf) patch_get_signal(freqtradebot, (True, False)) @@ -998,7 +993,6 @@ def test_performance_handle(default_conf, update, ticker, fee, get_ticker=ticker, get_fee=fee, markets=PropertyMock(markets), - validate_pairs=MagicMock(return_value={}) ) mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) freqtradebot = FreqtradeBot(default_conf) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index a67659d8c..2e5014e0c 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -2200,9 +2200,9 @@ def test_handle_timedout_limit_sell(mocker, default_conf) -> None: def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, markets, mocker) -> None: rpc_mock = patch_RPCManager(mocker) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets) @@ -2246,9 +2246,9 @@ def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, markets, moc def test_execute_sell_down(default_conf, ticker, fee, ticker_sell_down, markets, mocker) -> None: rpc_mock = patch_RPCManager(mocker) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets) @@ -2295,9 +2295,9 @@ def test_execute_sell_down_stoploss_on_exchange_dry_run(default_conf, ticker, fe ticker_sell_down, markets, mocker) -> None: rpc_mock = patch_RPCManager(mocker) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets) @@ -2352,9 +2352,9 @@ def test_execute_sell_sloe_cancel_exception(mocker, default_conf, ticker, fee, freqtrade = get_patched_freqtradebot(mocker, default_conf) mocker.patch('freqtrade.exchange.Exchange.cancel_order', side_effect=InvalidOrderException()) sellmock = MagicMock() + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets), @@ -2383,9 +2383,9 @@ def test_execute_sell_with_stoploss_on_exchange(default_conf, default_conf['exchange']['name'] = 'binance' rpc_mock = patch_RPCManager(mocker) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets) @@ -2438,9 +2438,9 @@ def test_may_execute_sell_after_stoploss_on_exchange_hit(default_conf, markets, mocker) -> None: default_conf['exchange']['name'] = 'binance' rpc_mock = patch_RPCManager(mocker) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets) @@ -2502,9 +2502,9 @@ def test_may_execute_sell_after_stoploss_on_exchange_hit(default_conf, def test_execute_sell_market_order(default_conf, ticker, fee, ticker_sell_up, markets, mocker) -> None: rpc_mock = patch_RPCManager(mocker) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets) @@ -2678,9 +2678,9 @@ def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, fee, marke def test_locked_pairs(default_conf, ticker, fee, ticker_sell_down, markets, mocker, caplog) -> None: patch_RPCManager(mocker) + patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - _load_markets=MagicMock(return_value={}), get_ticker=ticker, get_fee=fee, markets=PropertyMock(return_value=markets)