Skip to content

Commit

Permalink
Fix pytest 8.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
youtux committed Jan 11, 2025
1 parent ca52a05 commit 85c1776
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pytest_factoryboy/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ def create_fixture_with_related(
) -> Callable[P, T]:
if related is None:
related = []
f = create_fixture(name=name, function=function, fixtures=fixtures)
fixture, fn = create_fixture(name=name, function=function, fixtures=fixtures)

# 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.
f.__pytest_wrapped__.obj._factoryboy_related = related # type: ignore[attr-defined]
return f
fn._factoryboy_related = related # type: ignore[attr-defined]
return fixture


def make_declaration_fixturedef(
Expand Down
10 changes: 6 additions & 4 deletions pytest_factoryboy/fixturegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Callable, TypeVar

import pytest
from _pytest.fixtures import FixtureFunctionDefinition
from typing_extensions import ParamSpec

T = TypeVar("T")
Expand All @@ -16,13 +17,13 @@ def create_fixture(
name: str,
function: Callable[P, T],
fixtures: Collection[str] | None = None,
) -> Callable[P, T]:
) -> tuple[FixtureFunctionDefinition, 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``.
:return: The created fixture function.
:return: The created fixture function and the actual function.
Example:
Expand All @@ -41,13 +42,14 @@ def book(name, db):
if fixtures is None:
fixtures = []

@pytest.fixture(name=name)
@usefixtures(*fixtures)
@functools.wraps(function)
def fn(*args: P.args, **kwargs: P.kwargs) -> T:
return function(*args, **kwargs)

return fn
fixture = pytest.fixture(name=name, fixture_function=fn)

return fixture, fn


def usefixtures(*fixtures: str) -> Callable[[Callable[P, T]], Callable[P, T]]:
Expand Down

0 comments on commit 85c1776

Please sign in to comment.