Complete the code to parametrize the test with values 1, 2, and 3.
import pytest @pytest.mark.parametrize('num', [1]) def test_is_positive(num): assert num > 0
The @pytest.mark.parametrize decorator expects an iterable like a list or tuple. Here, a list [1, 2, 3] is used to pass the values.
Complete the code to skip the test when the parameter is 0.
import pytest @pytest.mark.parametrize('num', [0, 1, 2]) def test_non_zero(num): if num == 0: pytest.skip([1]) assert num != 0
pytest.skip().The pytest.skip() function takes a string message explaining why the test is skipped. Here, we provide a clear message.
Fix the error in the conditional parametrize to only run test for even numbers.
import pytest values = [1, 2, 3, 4] @pytest.mark.parametrize('num', [v for v in values if [1]]) def test_even(num): assert num % 2 == 0
The condition v % 2 == 0 correctly checks if a number is even by testing if the remainder when divided by 2 is zero.
Fill both blanks to parametrize test only for numbers greater than 2 and skip others.
import pytest values = [1, 2, 3, 4] @pytest.mark.parametrize('num', [v for v in values if v [1] [2]]) def test_greater_than_two(num): assert num > 2
The list comprehension filters values where v > 2, so only numbers greater than 2 are tested.
Fill all three blanks to parametrize test with uppercase strings only and skip lowercase.
import pytest words = ['Hello', 'WORLD', 'test', 'PYTHON'] @pytest.mark.parametrize('word', [w for w in words if w.[1]() == w]) def test_uppercase(word): if not word.isupper(): pytest.skip([2]) assert word.isupper() is [3]
lower() instead of upper() in the filter.The list comprehension uses w.upper() to check if the word is uppercase. The skip message explains skipping lowercase words. The assertion checks that word.isupper() is True.