【问题标题】:Pytest missing 1 required positional argument with fixturePytest 缺少 1 个必需的位置参数与夹具
【发布时间】:2023-02-06 00:13:20
【问题描述】:

我使用 vscode 作为 IDE

我编写了一个非常简单的 pytest fixture 用法,但是当 pytest 文档中的基本示例 fixture 运行良好时它不起作用:

@pytest.fixture
def declare_hexidict():
    hd = hexidict()
    rvc = ReferenceValueCluster()
    rv = ReferenceValue(init=3)
    hd_var = (hd, rvc, rv)
    return hd_var

def 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

我得到了测试摘要信息:

ERROR test/process/hexidict/test_hd_basic_function.py - TypeError: setitem_getitem() missing 1 required positional argument: 'declare_hexidict'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

【问题讨论】:

    标签: python pytest fixtures test-fixture


    【解决方案1】:

    pytest 无法识别 setitem_getitem 之类的测试,因此您应该将其重命名为test_setitem_getitem试试看:

    def test_setitem_getitem(declare_hexidict):
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 2017-03-27
      • 2019-11-12
      • 2019-12-23
      相关资源
      最近更新 更多