Testing

def inc(x):
    return x + 1


def test_inc():
    assert inc(3) == 5

Then run pytest.

Tests in comments

You can write tests in the documentation.

def inc(x: int):
    """ return the integer that follows x

    Args:
        x (int): a integer

    Returns:
        _int_: x+1
    
    >>> inc(2)
    3
    
    """
    return x + 1

In order to perform the tests, run:

pytest --doctest-modules

You can also create files test_XAIJZPAUZXIUZABIZABC.txt for instance containing

    # content of test_example.txt

    hello this is a doctest
    >>> x = 3
    >>> x
    3

See more information here: https://docs.pytest.org/en/stable/how-to/doctest.html