Test helpers

Additional test utilities complementing fastcore.test

test_raises

Context manager for testing exceptions. More ergonomic than test_fail for multi-line code blocks and allows optional message content validation.


source

test_raises


def test_raises(
    expected:Type[Exception], contains:str | None=None
):
with test_raises(ZeroDivisionError):
    1/0  # type: ignore

with test_raises(ZeroDivisionError, 'division by zero'):
    1/0  # type: ignore

test_afail

Async version of fastcore.test.test_fail. Test that an async function raises an exception.


source

test_afail


async def test_afail(
    f, msg:str='', contains:str='', args:NoneType=None, kwargs:NoneType=None
):

Like fastcore own ‘test_fail’, but async

test_is_not

Test that two objects are not the same instance. Complement to fastcore.test.test_is.


source

test_is_not


def test_is_not(
    a, b
):

test that a is not b