def _(when=FALSY_PREDICATES): @skip(reason="reason", when=when) @testable_test def test_fn(): assert True assert test_fn.ward_meta.marker == SkipMarker(reason="reason", when=when)
def skip( func_or_reason: Union[str, Callable, None] = None, *, reason: Optional[str] = None, when: Union[bool, Callable] = True, ): """ Decorator which can be used to optionally skip tests. Args: func_or_reason (object): The wrapped test function to skip. reason: The reason the test was skipped. May appear in output. when: Predicate function. Will be called immediately before the test is executed. If it evaluates to True, the test will be skipped. Otherwise the test will run as normal. """ if func_or_reason is None: return functools.partial(skip, reason=reason, when=when) if isinstance(func_or_reason, str): return functools.partial(skip, reason=func_or_reason, when=when) func = func_or_reason marker = SkipMarker(reason=reason, when=when) if hasattr(func, "ward_meta"): func.ward_meta.marker = marker # type: ignore[attr-defined] else: func.ward_meta = CollectionMetadata( marker=marker) # type: ignore[attr-defined] @functools.wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs) return wrapper
def _(cache=cache, when=FALSY_PREDICATES): def test_fn(): assert True t = Test(fn=test_fn, module_name=mod, marker=SkipMarker(when=when)) result = t.run(cache) assert result == TestResult(t, outcome=TestOutcome.PASS)
def _(): @skip @testable_test def test_fn(): assert True assert test_fn.ward_meta.marker == SkipMarker() assert test_fn.ward_meta.marker.active
def _(cache=cache, when=FALSY_PREDICATES): def test_fn(): assert 1 == 2 t = Test(fn=test_fn, module_name=mod, marker=SkipMarker(when=when)) result = t.run(cache) assert result.test == t assert result.outcome == TestOutcome.FAIL
def skip(func_or_reason=None, *, reason: str = None): if func_or_reason is None: return functools.partial(skip, reason=reason) if isinstance(func_or_reason, str): return functools.partial(skip, reason=func_or_reason) func = func_or_reason marker = SkipMarker(reason=reason) if hasattr(func, "ward_meta"): func.ward_meta.marker = marker else: func.ward_meta = WardMeta(marker=marker) @functools.wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs) return wrapper
def skipped_test(module=module): @testable_test def t(): assert 1 == 1 return Test(fn=t, module_name=module, marker=SkipMarker())
def skipped_test(module=module): return Test(fn=lambda: expect(1).equals(1), module_name=module, marker=SkipMarker())
def _(cache=cache, when=TRUTHY_PREDICATES): t = Test(fn=lambda: 1, module_name=mod, marker=SkipMarker(when=when)) result = t.run(cache) assert result == TestResult(t, outcome=TestOutcome.SKIP)
def _(when=FALSY_PREDICATES, ): skip_marker = SkipMarker(when=when) assert not skip_marker.active
def _(when=TRUTHY_PREDICATES, ): skip_marker = SkipMarker(when=when) assert skip_marker.active
def skipped_test(module=module): @testable_test def t(): expect(1).equals(1) return Test(fn=t, module_name=module, marker=SkipMarker())