def xfail( func_or_reason: Union[str, Callable, None] = None, *, reason: Optional[str] = None, when: Union[bool, Callable] = True, ): """ Decorator that can be used to mark a test as "expected to fail". Args: func_or_reason: The wrapped test function to mark as an expected failure. reason: The reason we expect the test to fail. 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 marked as an expected failure. Otherwise the test will run as normal. """ if func_or_reason is None: return functools.partial(xfail, reason=reason, when=when) if isinstance(func_or_reason, str): return functools.partial(xfail, reason=func_or_reason, when=when) func = func_or_reason marker = XfailMarker(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 _(when=FALSY_PREDICATES): @xfail(reason="reason", when=when) @testable_test def test_fn(): assert True assert test_fn.ward_meta.marker == XfailMarker(reason="reason", when=when)
def _(): @xfail() @testable_test def test_fn(): assert True assert test_fn.ward_meta.marker == XfailMarker()
def _(cache=cache, when=TRUTHY_PREDICATES): def test_fn(): assert 1 == 1 t = Test(fn=test_fn, module_name=mod, marker=XfailMarker(when=when)) result = t.run(cache) assert result.test == t assert result.outcome == TestOutcome.XPASS
def xfail(func_or_reason=None, *, reason: str = None): if func_or_reason is None: return functools.partial(xfail, reason=reason) if isinstance(func_or_reason, str): return functools.partial(xfail, reason=func_or_reason) func = func_or_reason marker = XfailMarker(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 _(when=FALSY_PREDICATES, ): xfail_marker = XfailMarker(when=when) assert not xfail_marker.active
def _(when=TRUTHY_PREDICATES, ): xfail_marker = XfailMarker(when=when) assert xfail_marker.active