Skip to content

Commit

Permalink
add type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmonMode committed Jan 28, 2020
1 parent 6db4724 commit f26c693
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/_pytest/fixtures.py
Expand Up @@ -6,8 +6,10 @@
from collections import defaultdict
from collections import deque
from collections import OrderedDict
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Tuple

import attr
Expand Down Expand Up @@ -886,15 +888,13 @@ def finish(self, request):
del self.cached_result
self._finalizers = []

def execute(self, request):
def execute(self, request: SubRequest) -> Optional[Any]:
for argname in self._dependee_fixture_argnames(request):
if argname == "request":
continue
fixturedef = request._get_active_fixturedef(argname)
if not self._will_be_finalized_by_fixture(fixturedef):
fixturedef.addfinalizer(
functools.partial(self.finish, request=request)
)
fixturedef.addfinalizer(functools.partial(self.finish, request=request))

my_cache_key = self.cache_key(request)
cached_result = getattr(self, "cached_result", None)
Expand All @@ -914,7 +914,7 @@ def execute(self, request):
hook = self._fixturemanager.session.gethookproxy(request.node.fspath)
return hook.pytest_fixture_setup(fixturedef=self, request=request)

def _will_be_finalized_by_fixture(self, fixturedef):
def _will_be_finalized_by_fixture(self, fixturedef: "FixtureDef") -> bool:
"""Whether or not this fixture be finalized by the passed fixture.
Every ``:class:FixtureDef`` keeps a list of all the finishers (tear downs) of
Expand All @@ -933,7 +933,7 @@ def _will_be_finalized_by_fixture(self, fixturedef):
return True
return False

def _dependee_fixture_argnames(self, request):
def _dependee_fixture_argnames(self, request: SubRequest) -> Tuple[str, ...]:
"""A list of argnames for fixtures that this fixture depends on.
Given a request, this looks at the currently known list of fixture argnames, and
Expand Down Expand Up @@ -976,7 +976,7 @@ def _dependee_fixture_argnames(self, request):
current_fix_index = len(request.fixturenames)
parent_fixture_indexes = set()

parent_request = request._parent_request
parent_request = getattr(request, "_parent_request")
while hasattr(parent_request, "_parent_request"):
if hasattr(parent_request, "_fixturedef"):
parent_fix_name = parent_request._fixturedef.argname
Expand All @@ -986,7 +986,7 @@ def _dependee_fixture_argnames(self, request):

stack_slice_index = min([current_fix_index, *parent_fixture_indexes])
active_fixture_argnames = all_fix_names[:stack_slice_index]
return tuple(active_fixture_argnames) + self.argnames
return tuple(tuple(active_fixture_argnames) + self.argnames)

def cache_key(self, request):
return request.param_index if not hasattr(request, "param") else request.param
Expand Down

0 comments on commit f26c693

Please sign in to comment.