Repository: pytest-dev/pytest
File: src/_pytest/fixtures.py (Python)

Code before:
                )
                fail(msg, pytrace=False)

        subrequest = SubRequest(
            self, scope, param, param_index, fixturedef, _ispytest=True
        )

        # Check if a higher-level scoped fixture accesses a lower level one.
        subrequest._check_scope(argname, self._scope, scope)
        # Make sure the fixture value is cached, running it if it isn't
        fixturedef.execute(request=subrequest)

    def _schedule_finalizers(
        self, fixturedef: "FixtureDef[object]", subrequest: "SubRequest"
    ) -> None:
        # If fixture function failed it might have registered finalizers.
        finalizer = functools.partial(fixturedef.finish, request=subrequest)
        subrequest.node.addfinalizer(finalizer)


@final
class TopRequest(FixtureRequest):
    """The type of the ``request`` fixture in a test function."""

    def __init__(self, pyfuncitem: "Function", *, _ispytest: bool = False) -> None:
        super().__init__(
            fixturename=None,
            pyfuncitem=pyfuncitem,
            arg2fixturedefs=pyfuncitem._fixtureinfo.name2fixturedefs.copy(),
            arg2index={},
            fixture_defs={},
            _ispytest=_ispytest,
        )

    @property
    def _scope(self) -> Scope:
        return Scope.Function

    @property
    def node(self):
        return self._pyfuncitem

    def __repr__(self) -> str:
        return "<FixtureRequest for %r>" % (self.node)

    def _fillfixtures(self) -> None:
        item = self._pyfuncitem
        for argname in item.fixturenames:
            if argname not in item.funcargs:
                item.funcargs[argname] = self.getfixturevalue(argname)


Review comment (suggestion):
Should remove the `_schedule_finalizers` functions since that's the only caller

Code after:
                source_path = absolutepath(frameinfo.filename)
                source_lineno = frameinfo.lineno
                try:
                    source_path_str = str(
                        source_path.relative_to(funcitem.config.rootpath)
                    )
                except ValueError:
                    source_path_str = str(source_path)
                location = getlocation(fixturedef.func, funcitem.config.rootpath)
                msg = (
                    "The requested fixture has no parameter defined for test:\n"
                    f"    {funcitem.nodeid}\n\n"
                    f"Requested fixture '{fixturedef.argname}' defined in:\n"
                    f"{location}\n\n"
                    f"Requested here:\n"
                    f"{source_path_str}:{source_lineno}"
                )
                fail(msg, pytrace=False)

        # Check if a higher-level scoped fixture accesses a lower level one.
        self._check_scope(fixturedef, scope)

        subrequest = SubRequest(
            self, scope, param, param_index, fixturedef, _ispytest=True
        )

        # Make sure the fixture value is cached, running it if it isn't
        fixturedef.execute(request=subrequest)


@final
class TopRequest(FixtureRequest):
    """The type of the ``request`` fixture in a test function."""

    def __init__(self, pyfuncitem: "Function", *, _ispytest: bool = False) -> None:
        super().__init__(
            fixturename=None,
            pyfuncitem=pyfuncitem,
            arg2fixturedefs=pyfuncitem._fixtureinfo.name2fixturedefs.copy(),
            fixture_defs={},
            _ispytest=_ispytest,
        )

    @property
    def _scope(self) -> Scope:
        return Scope.Function

    def _check_scope(
        self,
        requested_fixturedef: Union["FixtureDef[object]", PseudoFixtureDef[object]],
        requested_scope: Scope,