diff --git a/pytest_bdd/steps.py b/pytest_bdd/steps.py index 983ac05..6cd5fdf 100644 --- a/pytest_bdd/steps.py +++ b/pytest_bdd/steps.py @@ -127,25 +127,6 @@ def then( return step(name, THEN, converters=converters, target_fixture=target_fixture, stacklevel=stacklevel) -def find_unique_name(name: str, seen: Iterable[str]) -> str: - """Find unique name among a set of strings. - - New names are generated by appending an increasing number at the end of the name. - - Example: - >>> find_unique_name("foo", ["foo", "foo_1"]) - 'foo_2' - """ - seen = set(seen) - if name not in seen: - return name - - for i in count(1): - new_name = f"{name}_{i}" - if new_name not in seen: - return new_name - - def step( name: str | StepParser, type_: Literal["given", "when", "then"] | None = None, @@ -196,6 +177,25 @@ def step( return decorator +def find_unique_name(name: str, seen: Iterable[str]) -> str: + """Find unique name among a set of strings. + + New names are generated by appending an increasing number at the end of the name. + + Example: + >>> find_unique_name("foo", ["foo", "foo_1"]) + 'foo_2' + """ + seen = set(seen) + if name not in seen: + return name + + for i in count(1): + new_name = f"{name}_{i}" + if new_name not in seen: + return new_name + + def inject_fixture(request: FixtureRequest, arg: str, value: Any) -> None: """Inject fixture into pytest fixture request.