コード例 #1
0
ファイル: testing.py プロジェクト: darrenburns/ward
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
コード例 #2
0
ファイル: test_testing.py プロジェクト: AABur/ward
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)
コード例 #3
0
ファイル: test_testing.py プロジェクト: AABur/ward
def _():
    @xfail()
    @testable_test
    def test_fn():
        assert True

    assert test_fn.ward_meta.marker == XfailMarker()
コード例 #4
0
ファイル: test_testing.py プロジェクト: AABur/ward
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
コード例 #5
0
ファイル: testing.py プロジェクト: mkuyper/ward
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
コード例 #6
0
ファイル: test_models.py プロジェクト: gc-ss/ward
def _(when=FALSY_PREDICATES, ):
    xfail_marker = XfailMarker(when=when)
    assert not xfail_marker.active
コード例 #7
0
ファイル: test_models.py プロジェクト: gc-ss/ward
def _(when=TRUTHY_PREDICATES, ):
    xfail_marker = XfailMarker(when=when)
    assert xfail_marker.active