How do I parametrize tests in pytest?

Parametrizing tests in pytest allows you to run the same test function with different sets of parameters. This is particularly useful for testing functions with various input cases without writing separate test functions for each case.

Example of Parametrizing Tests in pytest

import pytest @pytest.mark.parametrize("input_value, expected_output", [ (1, 2), (2, 3), (3, 4), ]) def test_increment(input_value, expected_output): assert increment(input_value) == expected_output def increment(x): return x + 1

pytest parametrize testing python unit testing