Make sure backtesting is cleaned up in tests

This commit is contained in:
Matthias 2022-02-24 06:25:21 +01:00
parent 53452c8d64
commit 42df65d4ec
3 changed files with 11 additions and 4 deletions

View File

@ -128,7 +128,8 @@ class Backtesting:
def __del__(self):
self.cleanup()
def cleanup(self):
@staticmethod
def cleanup():
LoggingMixin.show_output = True
PairLocks.use_db = True
Trade.use_db = True

View File

@ -52,6 +52,13 @@ def trim_dictlist(dict_list, num):
return new
@pytest.fixture(autouse=True)
def backtesting_cleanup() -> None:
yield None
Backtesting.cleanup()
def load_data_test(what, testdatadir):
timerange = TimeRange.parse_timerange('1510694220-1510700340')
data = history.load_pair_history(pair='UNITTEST/BTC', datadir=testdatadir,
@ -553,8 +560,6 @@ def test_backtest__enter_trade(default_conf, fee, mocker) -> None:
trade = backtesting._enter_trade(pair, row=row)
assert trade is None
backtesting.cleanup()
def test_backtest__get_sell_trade_entry(default_conf, fee, mocker) -> None:
default_conf['use_sell_signal'] = False
@ -1423,7 +1428,7 @@ def test_get_strategy_run_id(default_conf_usdt):
default_conf_usdt.update({
'strategy': 'StrategyTestV2',
'max_open_trades': float('inf')
})
})
strategy = StrategyResolver.load_strategy(default_conf_usdt)
x = get_strategy_run_id(strategy)
assert isinstance(x, str)

View File

@ -1108,6 +1108,7 @@ def test_api_forcesell(botclient, mocker, ticker, fee, markets):
data='{"tradeid": "1"}')
assert_response(rc, 502)
assert rc.json() == {"error": "Error querying /api/v1/forcesell: invalid argument"}
Trade.query.session.rollback()
ftbot.enter_positions()