A sub request for handling getting a fixture from a test function/fixture.
| 760 | |
| 761 | @final |
| 762 | class SubRequest(FixtureRequest): |
| 763 | """A sub request for handling getting a fixture from a test function/fixture.""" |
| 764 | |
| 765 | def __init__( |
| 766 | self, |
| 767 | request: "FixtureRequest", |
| 768 | scope: Scope, |
| 769 | param: Any, |
| 770 | param_index: int, |
| 771 | fixturedef: "FixtureDef[object]", |
| 772 | *, |
| 773 | _ispytest: bool = False, |
| 774 | ) -> None: |
| 775 | check_ispytest(_ispytest) |
| 776 | self._parent_request = request |
| 777 | self.fixturename = fixturedef.argname |
| 778 | if param is not NOTSET: |
| 779 | self.param = param |
| 780 | self.param_index = param_index |
| 781 | self._scope = scope |
| 782 | self._fixturedef = fixturedef |
| 783 | self._pyfuncitem = request._pyfuncitem |
| 784 | self._fixture_defs = request._fixture_defs |
| 785 | self._arg2fixturedefs = request._arg2fixturedefs |
| 786 | self._arg2index = request._arg2index |
| 787 | self._fixturemanager = request._fixturemanager |
| 788 | |
| 789 | def __repr__(self) -> str: |
| 790 | return f"<SubRequest {self.fixturename!r} for {self._pyfuncitem!r}>" |
| 791 | |
| 792 | def addfinalizer(self, finalizer: Callable[[], object]) -> None: |
| 793 | """Add finalizer/teardown function to be called after the last test |
| 794 | within the requesting test context finished execution.""" |
| 795 | self._fixturedef.addfinalizer(finalizer) |
| 796 | |
| 797 | def _schedule_finalizers( |
| 798 | self, fixturedef: "FixtureDef[object]", subrequest: "SubRequest" |
| 799 | ) -> None: |
| 800 | # If the executing fixturedef was not explicitly requested in the argument list (via |
| 801 | # getfixturevalue inside the fixture call) then ensure this fixture def will be finished |
| 802 | # first. |
| 803 | if fixturedef.argname not in self.fixturenames: |
| 804 | fixturedef.addfinalizer( |
| 805 | functools.partial(self._fixturedef.finish, request=self) |
| 806 | ) |
| 807 | super()._schedule_finalizers(fixturedef, subrequest) |
| 808 | |
| 809 | |
| 810 | @final |
no outgoing calls
no test coverage detected