Test Overview
This test uses @pytest.mark.parametrize to run the same test function with different input values. It verifies that the function correctly doubles the input number.
This test uses @pytest.mark.parametrize to run the same test function with different input values. It verifies that the function correctly doubles the input number.
import pytest @pytest.mark.parametrize("input_value,expected", [ (1, 2), (5, 10), (0, 0), (-3, -6) ]) def test_double(input_value, expected): result = input_value * 2 assert result == expected, f"Expected {expected} but got {result}"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts with parameter input_value=1 and expected=2 | Test environment ready, no browser involved | Check if 1 * 2 equals 2 | PASS |
| 2 | Test runs with parameter input_value=5 and expected=10 | Test environment ready | Check if 5 * 2 equals 10 | PASS |
| 3 | Test runs with parameter input_value=0 and expected=0 | Test environment ready | Check if 0 * 2 equals 0 | PASS |
| 4 | Test runs with parameter input_value=-3 and expected=-6 | Test environment ready | Check if -3 * 2 equals -6 | PASS |
@pytest.mark.parametrize decorator in pytest?@pytest.mark.parametrize allows running one test function multiple times with different inputs.@pytest.mark.parametrize for testing a function with inputs 1 and 2?@pytest.mark.parametrize with parameters as strings and list of values.import pytest
@pytest.mark.parametrize('x,y', [(1,2), (3,4)])
def test_sum(x, y):
assert x + y == 3@pytest.mark.parametrize:@pytest.mark.parametrize('num', [1, 2, 3])
def test_even():
assert num % 2 == 0is_valid_age(age) that returns True if age is between 18 and 65 inclusive. Which @pytest.mark.parametrize usage correctly tests ages 17, 18, 30, 65, and 70 with expected results?Pass the test and this pattern moves unknown