Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def scope_key_from(self, scope: Scope) -> ScopeKey:
if scope == Scope.Test:
return self.id
elif scope == Scope.Module:
return self.path
else:
return Scope.Global
@fixture(scope=Scope.Module)
def b():
events.append("resolve b")
yield "b"
events.append("teardown b")
@fixture(scope=Scope.Module)
def a():
events.append("resolve")
yield "a"
events.append("teardown")
name: str = "SKIP"
reason: Optional[str] = None
@dataclass
class XfailMarker(Marker):
name: str = "XFAIL"
reason: Optional[str] = None
@dataclass
class WardMeta:
marker: Optional[Marker] = None
description: Optional[str] = None
is_fixture: bool = False
scope: Scope = Scope.Test
bound_args: Optional[BoundArguments] = None
path: Optional[str] = None
def deps(self):
return inspect.signature(self.fn).parameters
def teardown(self):
# Suppress because we can't know whether there's more code
# to execute below the yield.
with suppress(StopIteration, RuntimeError):
if self.is_generator_fixture and self.gen:
next(self.gen)
FixtureKey = str
TestId = str
ModulePath = str
ScopeKey = Union[TestId, ModulePath, Scope]
ScopeCache = Dict[Scope, Dict[ScopeKey, Dict[FixtureKey, Fixture]]]
def _scope_cache_factory():
return {scope: {} for scope in Scope}
@dataclass
class FixtureCache:
"""
A collection of caches, each storing data for a different scope.
When a fixture is resolved, it is stored in the appropriate cache given
the scope of the fixture.
A lookup into this cache is a 3 stage process: