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

Function pytest_fixture_setup

src/_pytest/fixtures.py:1305–1338  ·  view source on GitHub ↗

Execution of fixture setup.

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

Source from the content-addressed store, hash-verified

1303
1304
1305def pytest_fixture_setup(
1306 fixturedef: FixtureDef[FixtureValue], request: SubRequest
1307) -> FixtureValue:
1308 """Execution of fixture setup."""
1309 kwargs = {}
1310 for argname in fixturedef.argnames:
1311 kwargs[argname] = request.getfixturevalue(argname)
1312
1313 fixturefunc = resolve_fixture_function(fixturedef, request)
1314 my_cache_key = fixturedef.cache_key(request)
1315
1316 if inspect.isasyncgenfunction(fixturefunc) or inspect.iscoroutinefunction(
1317 fixturefunc
1318 ):
1319 auto_str = " with autouse=True" if fixturedef._autouse else ""
1320 fail(
1321 f"{request.node.name!r} requested an async fixture {request.fixturename!r}{auto_str}, "
1322 "with no plugin or hook that handled it. This is an error, as pytest does not natively support it.\n"
1323 "See: https://docs.pytest.org/en/stable/deprecations.html#sync-test-depending-on-async-fixture",
1324 pytrace=False,
1325 )
1326
1327 try:
1328 result = call_fixture_func(fixturefunc, request, kwargs)
1329 except TEST_OUTCOME as e:
1330 if isinstance(e, skip.Exception):
1331 # The test requested a fixture which caused a skip.
1332 # Don't show the fixture as the skip location, as then the user
1333 # wouldn't know which test skipped.
1334 e._use_item_location = True
1335 fixturedef.cached_result = (None, my_cache_key, (e, e.__traceback__))
1336 raise
1337 fixturedef.cached_result = (result, my_cache_key, None)
1338 return result
1339
1340
1341@final

Callers

nothing calls this directly

Calls 4

resolve_fixture_functionFunction · 0.85
call_fixture_funcFunction · 0.85
getfixturevalueMethod · 0.80
cache_keyMethod · 0.80

Tested by

no test coverage detected