Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/pytest_factoryboy/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def generate_fixtures(
create_fixture_with_related(
name=model_name,
function=functools.partial(model_fixture, factory_name=factory_name),
fixtures=deps,
dependencies=deps,
related=related,
),
)
Expand All @@ -196,12 +196,12 @@ def generate_fixtures(
def create_fixture_with_related(
name: str,
function: Callable[P, T],
fixtures: Collection[str] | None = None,
dependencies: Collection[str] | None = None,
related: Collection[str] | None = None,
) -> Callable[P, T]:
if related is None:
related = []
fixture, fn = create_fixture(name=name, function=function, fixtures=fixtures)
fixture, fn = create_fixture(name=name, function=function, dependencies=dependencies)

# We have to set the `_factoryboy_related` attribute to the original function, since
# FixtureDef.func will provide that one later when we discover the related fixtures.
Expand Down Expand Up @@ -234,7 +234,7 @@ def make_declaration_fixturedef(
return create_fixture_with_related(
name=attr_name,
function=functools.partial(subfactory_fixture, factory_class=subfactory_class),
fixtures=args,
dependencies=args,
)

deps: list[str] # makes mypy happy
Expand All @@ -254,7 +254,7 @@ def make_declaration_fixturedef(
return create_fixture_with_related(
name=attr_name,
function=functools.partial(attr_fixture, value=value),
fixtures=deps,
dependencies=deps,
)


Expand Down
10 changes: 5 additions & 5 deletions src/pytest_factoryboy/fixturegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
def create_fixture(
name: str,
function: Callable[P, T],
fixtures: Collection[str] | None = None,
dependencies: Collection[str] | None = None,
) -> tuple[PytestFixtureT, Callable[P, T]]:
"""Dynamically create a pytest fixture.
:param name: Name of the fixture.
:param function: Function to be called.
:param fixtures: List of fixtures dependencies, but that will not be passed to ``function``.
:param dependencies: List of fixtures dependencies, but that will not be passed to ``function``.
:return: The created fixture function and the actual function.
Example:
Expand All @@ -40,10 +40,10 @@ def create_fixture(
def book(name, db):
return Book(name=name)
"""
if fixtures is None:
fixtures = []
if dependencies is None:
dependencies = []

@usefixtures(*fixtures)
@usefixtures(*dependencies)
@functools.wraps(function)
def fn(*args: P.args, **kwargs: P.kwargs) -> T:
return function(*args, **kwargs)
Expand Down
Loading