Skip to content

Commit d217d68

Browse files
bluetechnicoddemus
authored andcommitted
fixtures: inline _compute_fixture_value
1 parent 530be28 commit d217d68

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/_pytest/fixtures.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -582,26 +582,7 @@ def _get_active_fixturedef(
582582
return PseudoFixtureDef(cached_result, Scope.Function)
583583
raise
584584

585-
self._compute_fixture_value(fixturedef)
586-
587-
self._fixture_defs[argname] = fixturedef
588-
return fixturedef
589-
590-
def _get_fixturestack(self) -> List["FixtureDef[Any]"]:
591-
values = [request._fixturedef for request in self._iter_chain()]
592-
values.reverse()
593-
return values
594-
595-
def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
596-
"""Create a SubRequest based on "self" and call the execute method
597-
of the given FixtureDef object.
598-
599-
If the FixtureDef has cached the result it will do nothing, otherwise it will
600-
setup and run the fixture, cache the value, and schedule a finalizer for it.
601-
"""
602-
# prepare a subrequest object before calling fixture function
603-
# (latter managed by fixturedef)
604-
argname = fixturedef.argname
585+
# Prepare a SubRequest object for calling the fixture.
605586
funcitem = self._pyfuncitem
606587
try:
607588
callspec = funcitem.callspec
@@ -627,7 +608,7 @@ def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
627608
)
628609
fail(msg, pytrace=False)
629610
if has_params:
630-
frame = inspect.stack()[3]
611+
frame = inspect.stack()[2]
631612
frameinfo = inspect.getframeinfo(frame[0])
632613
source_path = absolutepath(frameinfo.filename)
633614
source_lineno = frameinfo.lineno
@@ -658,6 +639,14 @@ def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
658639
# Make sure the fixture value is cached, running it if it isn't
659640
fixturedef.execute(request=subrequest)
660641

642+
self._fixture_defs[argname] = fixturedef
643+
return fixturedef
644+
645+
def _get_fixturestack(self) -> List["FixtureDef[Any]"]:
646+
values = [request._fixturedef for request in self._iter_chain()]
647+
values.reverse()
648+
return values
649+
661650

662651
@final
663652
class TopRequest(FixtureRequest):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy