Define a pytest fixture providing multiple arguments to test function

后端 未结 2 1453
猫巷女王i
猫巷女王i 2020-12-19 17:38

With pytest, I can define a fixture like so:

@pytest.fixture
def foo():
    return \"blah\"

And use it in a test like so:

d         


        
2条回答
  •  盖世英雄少女心
    2020-12-19 17:59

    You can now do this using pytest-cases:

    from pytest_cases import fixture
    
    @fixture(unpack_into="foo,bar")
    def foobar():
        return "blah", "whatever"
    
    def test_stuff(foo, bar):
        assert foo == "blah" and bar == "whatever"
    

    See the documentation for more details (I'm the author by the way)

提交回复
热议问题