Skip to content

Commit 85c1776

Browse files
committed
Fix pytest 8.4 compatibility
1 parent ca52a05 commit 85c1776

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pytest_factoryboy/fixture.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ def create_fixture_with_related(
182182
) -> Callable[P, T]:
183183
if related is None:
184184
related = []
185-
f = create_fixture(name=name, function=function, fixtures=fixtures)
185+
fixture, fn = create_fixture(name=name, function=function, fixtures=fixtures)
186186

187187
# We have to set the `_factoryboy_related` attribute to the original function, since
188188
# FixtureDef.func will provide that one later when we discover the related fixtures.
189-
f.__pytest_wrapped__.obj._factoryboy_related = related # type: ignore[attr-defined]
190-
return f
189+
fn._factoryboy_related = related # type: ignore[attr-defined]
190+
return fixture
191191

192192

193193
def make_declaration_fixturedef(

pytest_factoryboy/fixturegen.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Callable, TypeVar
77

88
import pytest
9+
from _pytest.fixtures import FixtureFunctionDefinition
910
from typing_extensions import ParamSpec
1011

1112
T = TypeVar("T")
@@ -16,13 +17,13 @@ def create_fixture(
1617
name: str,
1718
function: Callable[P, T],
1819
fixtures: Collection[str] | None = None,
19-
) -> Callable[P, T]:
20+
) -> tuple[FixtureFunctionDefinition, Callable[P, T]]:
2021
"""Dynamically create a pytest fixture.
2122
2223
:param name: Name of the fixture.
2324
:param function: Function to be called.
2425
:param fixtures: List of fixtures dependencies, but that will not be passed to ``function``.
25-
:return: The created fixture function.
26+
:return: The created fixture function and the actual function.
2627
2728
Example:
2829
@@ -41,13 +42,14 @@ def book(name, db):
4142
if fixtures is None:
4243
fixtures = []
4344

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

50-
return fn
50+
fixture = pytest.fixture(name=name, fixture_function=fn)
51+
52+
return fixture, fn
5153

5254

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

0 commit comments

Comments
 (0)