You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode中Pytest Fixture报错:缺少必填位置参数declare_hexidict

问题原因及解决办法

核心问题

你的测试函数命名不符合Pytest的规则——Pytest默认只会把以test_开头的函数识别为测试用例。你写的setitem_getitem没有这个前缀,导致Pytest没有按照测试函数的逻辑处理它,也就不会自动注入declare_hexidict这个fixture参数,最终抛出参数缺失的错误。

修复步骤

直接修改测试函数的名称,给它加上test_前缀:

def test_setitem_getitem(declare_hexidict):
    print('start')
    # hd = hexidict()
    # rvc = ReferenceValueCluster()
    # rv = ReferenceValue(init=3)
    hd, rvc, rv = declare_hexidict
    print('datastruct defined')
    hd[rvc("key1").reflink] = rv[0].reflink
    hd[rvc["key1"]] == rv[0]
    assert rvc["key1"] in hd.keys(), "key :{} is not int this hexidict".format(
        rvc("key1")
    )
    assert hd[rvc["key1"]] == rv[0], "key :{}  return {} instead of {}".format(
        rvc["key1"], hd[rvc["key1"]], rv[0]
    )
    #set non value item (on set une liste)
    hd[rvc("key2").reflink] = [rv[1].reflink]
    hd[rvc["key2"]]
    assert type(hd[rvc["key2"]]) == list

    #on verifie que l'item dans la list est bien celui qui provient de rv
    assert hd[rvc["key2"]][0] in rv

验证

修改后重新运行Pytest,它会正确识别这个测试函数,并自动注入declare_hexidict fixture,你的测试逻辑就能正常执行了。

内容的提问来源于stack exchange,提问作者Chrys Bltr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 16:20:42