Move function

This commit is contained in:
Alessio Bogon 2022-08-14 09:50:38 +02:00
parent 1ecd85171e
commit c7d3a1edfd
1 changed files with 19 additions and 19 deletions

View File

@ -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.