import pytest
# Flag to control which parameters to test
run_extended_tests = False
# Define test data with a condition
params = [
(1, 2, 3, True), # (a, b, expected, run_test)
(3, 5, 8, True),
(10, 20, 30, False),
(0, 0, 0, True)
]
# Filter parameters based on the flag
filtered_params = [ (a, b, expected) for a, b, expected, run_test in params if run_test or run_extended_tests ]
@pytest.mark.parametrize("a,b,expected", filtered_params)
def test_addition(a, b, expected):
assert a + b == expected
This test script uses pytest.mark.parametrize to run the test_addition function with multiple sets of inputs.
The params list includes a boolean flag run_test to indicate if the test case should run by default.
The filtered_params list comprehension filters the parameters based on the run_extended_tests flag. If run_extended_tests is False, only parameters with run_test=True are included.
This way, you can control which test cases run conditionally without changing the test code.
The assertion checks that the sum of a and b equals the expected result.