小编cdd*_*ura的帖子

由于 Mock 的 StopIteration 错误,Python 单元测试失败

我正在使用模拟测试一个类对象,即 ccxt.binance。这个模拟对象作为参数传递给我正在测试的函数。最初它是有效的,因为我能够在一定程度上进行测试。但是,当我更改所述对象的值时,该函数不尊重该值并返回 StopIteration 错误。我在模拟设置中遗漏了什么吗?这是代码的示例片段。

这是正在测试的代码

def exchange_history_load(args, ccxt_exchange):
    # skip exchange if has no true fetchOHLCV or if exchange has no timeframe specific data
    if ((not ccxt_exchange.has['fetchOHLCV']) or (ccxt_exchange.has['fetchOHLCV'] == 'emulated') or
       (not ccxt_exchange.timeframes.get(args.timeframe))):
        logging.warning(f'Skipping {ccxt_exchange.name}.')
        return

    # check if exchange is in database. Write to database if not.
    exchange_db_data = get_exchange(ccxt_exchange.id)
    if not exchange_db_data:
        insert_exchange_to_db(ccxt_exchange.id, ccxt_exchange.name)
        logging.info(f'Inserted {ccxt_exchange.name} to database.')
        exchange_db_data = get_exchange(ccxt_exchange.id)
    exchange_db_id = exchange_db_data[0]
    logging.info(f'Fetched {ccxt_exchange.name} data.')

    # load exchange markets
    markets = ccxt_exchange.load_markets()
    logging.info(f'Loaded {ccxt_exchange.name} markets.') …
Run Code Online (Sandbox Code Playgroud)

python-3.x ccxt

5
推荐指数
2
解决办法
4207
查看次数

标签 统计

ccxt ×1

python-3.x ×1