Don't use global variable in test

This commit is contained in:
Matthias
2023-08-15 16:53:21 +02:00
parent 5d3f3fb39f
commit 09ec00888f
+2 -3
View File
@@ -1122,10 +1122,10 @@ def test_backtest_dataprovider_analyzed_df(default_conf, fee, mocker, testdatadi
processed = backtesting.strategy.advise_all_indicators(data) processed = backtesting.strategy.advise_all_indicators(data)
min_date, max_date = get_timerange(processed) min_date, max_date = get_timerange(processed)
global count
count = 0 count = 0
def tmp_confirm_entry(pair, current_time, **kwargs): def tmp_confirm_entry(pair, current_time, **kwargs):
nonlocal count
dp = backtesting.strategy.dp dp = backtesting.strategy.dp
df, _ = dp.get_analyzed_dataframe(pair, backtesting.strategy.timeframe) df, _ = dp.get_analyzed_dataframe(pair, backtesting.strategy.timeframe)
current_candle = df.iloc[-1].squeeze() current_candle = df.iloc[-1].squeeze()
@@ -1135,8 +1135,7 @@ def test_backtest_dataprovider_analyzed_df(default_conf, fee, mocker, testdatadi
assert candle_date == current_time assert candle_date == current_time
# These asserts don't properly raise as they are nested, # These asserts don't properly raise as they are nested,
# therefore we increment count and assert for that. # therefore we increment count and assert for that.
global count count += 1
count = count + 1
backtesting.strategy.confirm_trade_entry = tmp_confirm_entry backtesting.strategy.confirm_trade_entry = tmp_confirm_entry
backtesting.backtest( backtesting.backtest(