I have a pytest.fixture
that has one positional arg and one keyword arg.
Per Pass a parameter to a fixture function, one can pass args to a fixture using pytest.mark.parametrize
with the indirect
arg set to the fixture's name.
Please see the below sample code.
import pytest
class Foo:
def __init__(self, a: str, b: str):
self.a = a
self.b = b
@pytest.fixture
def a() -> str:
return "alphabet"
@pytest.fixture
def foo_obj(a: str, b: str = "bar") -> Foo:
return Foo(a, b)
@pytest.mark.parametrize("foo_obj", [("applesauce", "baz")], indirect=["foo_obj"])
def test_thing(foo_obj) -> None:
assert foo_obj.a == "applesauce"
assert foo_obj.b == "baz"
This test fails currently: the "applesauce"
and "baz"
aren't getting passed into the fixture foo_obj
.
My questions:
- What am I doing wrong in passing the args to the fixture
foo_obj
? - Is it possible to only enter the kwarg
b
in thepytest.mark.parametrize
decorator call?- Note: I am not interested in wrapping the fixture as suggested here: Can I pass arguments to pytest fixtures?
Versions
Python==3.8.5
pytest==6.0.1