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

Method getfixturevalue

src/_pytest/fixtures.py:604–635  ·  view source on GitHub ↗

Dynamically run a named fixture function. Declaring fixtures via function argument is recommended where possible. But if you can only decide whether to use another fixture at test setup time, you may use this function to retrieve it inside a fixture or test function

(self, argname: str)

Source from the content-addressed store, hash-verified

602 raise FixtureLookupError(argname, self, msg)
603
604 def getfixturevalue(self, argname: str) -> Any:
605 """Dynamically run a named fixture function.
606
607 Declaring fixtures via function argument is recommended where possible.
608 But if you can only decide whether to use another fixture at test
609 setup time, you may use this function to retrieve it inside a fixture
610 or test function body.
611
612 This method can be used during the test setup phase or the test run
613 phase. Avoid using it during the teardown phase.
614
615 .. versionchanged:: 9.1
616 Calling ``request.getfixturevalue()`` during teardown to request a
617 fixture that was not already requested
618 :ref:`is deprecated <dynamic-fixture-request-during-teardown>`.
619
620 :param argname:
621 The fixture name.
622 :raises pytest.FixtureLookupError:
623 If the given fixture could not be found.
624 """
625 # Note that in addition to the use case described in the docstring,
626 # getfixturevalue() is also called by pytest itself during item and fixture
627 # setup to evaluate the fixtures that are requested statically
628 # (using function parameters, autouse, etc).
629
630 fixturedef = self._get_active_fixturedef(argname)
631 assert fixturedef.cached_result is not None, (
632 f'The fixture value for "{argname}" is not available. '
633 "This can happen when the fixture has already been torn down."
634 )
635 return fixturedef.cached_result[0]
636
637 def _iter_chain(self) -> Iterator[SubRequest]:
638 """Yield all SubRequests in the chain, from self up.

Callers 10

setupMethod · 0.80
_fillfixturesMethod · 0.80
pytest_fixture_setupFunction · 0.80
pdb_envFunction · 0.80
pdblistMethod · 0.80
test_getfixturevalueMethod · 0.80
aFunction · 0.80
arg1Function · 0.80
arg2Function · 0.80

Calls 1

Tested by 8

setupMethod · 0.64
pdb_envFunction · 0.64
pdblistMethod · 0.64
test_getfixturevalueMethod · 0.64
aFunction · 0.64
arg1Function · 0.64
arg2Function · 0.64