pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.31k stars 220 forks source link

Can't set defaults for step arguments #151

Closed dangitall closed 9 years ago

dangitall commented 9 years ago

I'd like to be able to write a step specification like this:

@given('there is an object')
@given(parsers.parse('there is an object named {name:s}'))
def obj(name="default"):
    return name

But if I do this then name always gets set to "default" even if the second step definition is used. Is there another way to achieve something like this? Or can defaults be supported for step arguments?

dangitall commented 9 years ago

After reading over the docs again I came up with this workaround:

@pytest.fixture
def name():
    return "default"

@given('there is an object')
@given(parsers.parse('there is an object named {name:s}'))
def obj(name):
    return name

Which isn't too bad but it still seems like it would be nice if defaults were directly supported.

bubenkoff commented 9 years ago

pytest-bdd is just a pytest plugin, in the end it doesn't do what pytest cannot do either, and there's no concept of defaults for fixtures in pytest so i like your second solution, and it's how we do it as well in paylogic test suite