Complete the code to write a simple pytest test function that checks if 2 + 2 equals 4.
def test_addition(): assert 2 + 2 == [1]
The correct answer is 4 because 2 + 2 equals 4. This assertion checks the expected result.
Complete the code to use a pytest fixture named 'sample_data' in the test function.
@pytest.fixture def sample_data(): return [1, 2, 3] def test_sum([1]): assert sum(sample_data) == 6
The test function must accept the fixture name 'sample_data' as a parameter to use it.
Fix the error in the test function by completing the assertion to check if the list is empty.
def test_empty_list(): my_list = [] assert [1](my_list)
Using 'not' before the list checks if the list is empty (False when empty).
Fill both blanks to create a parametrized pytest test that checks if numbers are even.
@pytest.mark.parametrize('num', [2, 3, 4]) def test_even(num): assert num [1] 2 == 0 assert isinstance(num, [2])
The modulus operator '%' checks remainder. 'int' checks the type of num.
Fill all three blanks to create a test that uses a fixture, asserts a condition, and checks type.
@pytest.fixture def data(): return {'a': 1, 'b': 2} def test_data([1]): assert [2]['a'] == 1 assert isinstance([3], dict)
The fixture name 'data' is used as parameter and variable to access the dictionary.