MCPcopy
hub / github.com/pytest-dev/pytest / resolve_fixture_function

Function resolve_fixture_function

src/_pytest/fixtures.py:1271–1302  ·  view source on GitHub ↗

Get the actual callable that can be called to obtain the fixture value.

(
    fixturedef: FixtureDef[FixtureValue], request: FixtureRequest
)

Source from the content-addressed store, hash-verified

1269
1270
1271def resolve_fixture_function(
1272 fixturedef: FixtureDef[FixtureValue], request: FixtureRequest
1273) -> _FixtureFunc[FixtureValue]:
1274 """Get the actual callable that can be called to obtain the fixture
1275 value."""
1276 fixturefunc = fixturedef.func
1277 # The fixture function needs to be bound to the actual
1278 # request.instance so that code working with "fixturedef" behaves
1279 # as expected.
1280 instance = request.instance
1281
1282 if fixturedef._scope is Scope.Class:
1283 # Check if fixture is an instance method (bound to instance, not class)
1284 if hasattr(fixturefunc, "__self__"):
1285 bound_to = fixturefunc.__self__
1286 # classmethod: bound_to is the class itself (a type)
1287 # instance method: bound_to is an instance (not a type)
1288 if not isinstance(bound_to, type):
1289 warnings.warn(CLASS_FIXTURE_INSTANCE_METHOD, stacklevel=2)
1290
1291 if instance is not None:
1292 # Handle the case where fixture is defined not in a test class, but some other class
1293 # (for example a plugin class with a fixture), see #2270.
1294 if hasattr(fixturefunc, "__self__") and not isinstance(
1295 instance,
1296 fixturefunc.__self__.__class__,
1297 ):
1298 return fixturefunc
1299 fixturefunc = getimfunc(fixturedef.func)
1300 if fixturefunc != fixturedef.func:
1301 fixturefunc = fixturefunc.__get__(instance)
1302 return fixturefunc
1303
1304
1305def pytest_fixture_setup(

Callers 1

pytest_fixture_setupFunction · 0.85

Calls 3

getimfuncFunction · 0.90
__get__Method · 0.80
warnMethod · 0.45

Tested by

no test coverage detected