What if you could test many inputs with just one simple test function?
Why Single parameter in PyTest? - Purpose & Use Cases
Imagine you have a function that needs to be tested with many different input values. You write a separate test for each input by hand, repeating almost the same code again and again.
This manual way is slow and boring. You might forget to test some inputs or make mistakes copying code. It's hard to keep tests organized and update them when the function changes.
Using a single parameter with pytest's @pytest.mark.parametrize lets you write one test that runs many times with different inputs automatically. This saves time, reduces errors, and keeps tests clean.
def test_add(): assert add(1) == 2 assert add(2) == 3 assert add(3) == 4
import pytest @pytest.mark.parametrize('input', [1, 2, 3]) def test_add(input): assert add(input) == input + 1
You can easily test many input cases with one simple test, making your testing faster and more reliable.
Testing a calculator app's add function with many numbers without writing repetitive tests for each number.
Manual repetitive tests are slow and error-prone.
Single parameter testing runs one test many times with different inputs.
This makes tests easier to write, read, and maintain.