pythonpytestfixturestest-fixture

Pytest missing 1 required positional argument with fixture


I'm using vscode as IDE

I have code a very simple usage of pytest fixture but it doesn't working when basic example fixture found in the pytest documentation are working well :

@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

I get in the test summary info :

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

Solution

  • pytest does not recognize setitem_getitem like test, so you should rename it to test_setitem_getitem and try it out:

    def test_setitem_getitem(declare_hexidict):