Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing the isalnum method

The stdtypes have a number of methods that return a boolean. Such functions are excellent to demonstrate parametrization.

import pytest


@pytest.mark.parametrize("val", ["a", "b", "א", "2"])
def test_isalnum(val):
    assert val.isalnum()

@pytest.mark.parametrize("val", ["_", " "])
def test_not_isalnum(val):
    assert not val.isalnum()

cpython tests