Closed bulletRush closed 2 years ago
You can use fixtures for default parameters as a workaround. I have done this in the past for table parameters.
@ktzoulas You don't understand what I mean. for a better e.g.
@then("the goods should sold out", available=True)
@then("the goods should not sold out", available=False)
def step_check_sold_out(ava, available=True):
assert ava == available
in current pytest-bdd version, you need write two step defs: step_check_sold_out and step_check_not_sold_out. but in my version, only need on step def.
@bulletRush could you please check https://github.com/elchupanebrej/pytest-bdd-ng and give your feedback if it covers your needs?
You can use a parser to achieve that result:
from pytest_bdd import then, parsers
@then(
parsers.re("the goods should (?P<negation>not )sold out"),
converters={"negation": bool},
)
def step_check_sold_out(ava, negation):
assert ava == not negation
You can also extend the pytest_bdd.parsers.StepParser
base class, and add this logic in the parse_arguments(...)
method. That's what this abstract base class is for.
for this situation:
currently, we need write four step implements. in my ext version, we can write step impl like:
if this feature is acceptable, i can make a PR to the latest version.
see commits: