Complete the code to import the pytest module needed for parameterization.
import [1]
We use pytest to enable parameterized tests in Python.
Complete the code to add the pytest decorator for parameterizing the test with two inputs.
@pytest.mark.[1]("input,expected") def test_example(input, expected): assert input + 1 == expected
The @pytest.mark.parametrize decorator allows running the test with different inputs.
Fix the error in the parameterized test data format by completing the code.
@pytest.mark.parametrize("input,expected", [ (1, 2), (2, [1]), (3, 4) ]) def test_add_one(input, expected): assert input + 1 == expected
The expected value for input 2 should be 3, since 2 + 1 = 3.
Fill both blanks to create a parameterized test that checks if a string contains a substring.
@pytest.mark.parametrize("text,substring") def test_contains(text, substring): assert [1] in [2]
The test checks if the substring is inside the text, so substring in text is correct.
Fill all three blanks to create a parameterized test that checks if a number is within a range.
@pytest.mark.parametrize("num,low,high") def test_in_range(num, low, high): assert [1] <= [2] <= [3]
The test asserts that num is between low and high, so the correct order is low <= num <= high.