Пример #1
0
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)
Пример #2
0
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
Пример #3
0
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)
Пример #4
0
def _():
    @skip
    @testable_test
    def test_fn():
        assert True

    assert test_fn.ward_meta.marker == SkipMarker()
    assert test_fn.ward_meta.marker.active
Пример #5
0
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
Пример #6
0
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
Пример #7
0
def skipped_test(module=module):
    @testable_test
    def t():
        assert 1 == 1

    return Test(fn=t, module_name=module, marker=SkipMarker())
Пример #8
0
def skipped_test(module=module):
    return Test(fn=lambda: expect(1).equals(1),
                module_name=module,
                marker=SkipMarker())
Пример #9
0
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)
Пример #10
0
def _(when=FALSY_PREDICATES, ):
    skip_marker = SkipMarker(when=when)
    assert not skip_marker.active
Пример #11
0
def _(when=TRUTHY_PREDICATES, ):
    skip_marker = SkipMarker(when=when)
    assert skip_marker.active
Пример #12
0
def skipped_test(module=module):
    @testable_test
    def t():
        expect(1).equals(1)

    return Test(fn=t, module_name=module, marker=SkipMarker())