How to use the ward.models.Scope function in ward

To help you get started, we’ve selected a few ward examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github darrenburns / ward / ward / testing.py View on Github external
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
github darrenburns / ward / tests / test_suite.py View on Github external
    @fixture(scope=Scope.Module)
    def b():
        events.append("resolve b")
        yield "b"
        events.append("teardown b")
github darrenburns / ward / tests / test_suite.py View on Github external
    @fixture(scope=Scope.Module)
    def a():
        events.append("resolve")
        yield "a"
        events.append("teardown")
github darrenburns / ward / ward / models.py View on Github external
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
github darrenburns / ward / ward / fixtures.py View on Github external
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: