66from typing import Callable , TypeVar
77
88import pytest
9+ from _pytest .fixtures import FixtureFunctionDefinition
910from typing_extensions import ParamSpec
1011
1112T = 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
5355def usefixtures (* fixtures : str ) -> Callable [[Callable [P , T ]], Callable [P , T ]]:
0 commit comments