Complete the code to check if the function raises a ValueError for invalid input.
import pytest def test_invalid_input(): with pytest.raises([1]): process_data('bad_input')
The test checks that process_data raises a ValueError when given bad input, which is a common error path to test for robustness.
Complete the assertion to verify the error message contains the word 'invalid'.
import pytest def test_error_message(): with pytest.raises(ValueError) as excinfo: process_data('bad_input') assert '[1]' in str(excinfo.value)
The assertion checks that the error message includes the word 'invalid', confirming the error path is correctly triggered.
Fix the error in the test that tries to catch a KeyError but the function raises ValueError.
import pytest def test_wrong_exception(): with pytest.raises([1]): process_data('bad_input')
The function raises a ValueError, so the test must expect that exception to pass.
Fill both blanks to test that the function raises a TypeError when input is not a string and the error message contains 'type'.
import pytest def test_type_error(): with pytest.raises([1]) as excinfo: process_data(123) assert '[2]' in str(excinfo.value)
The test expects a TypeError when input is not a string, and checks the error message contains 'type' to confirm the cause.
Fill all three blanks to create a test that asserts a KeyError is raised when a missing key is accessed, and the error message contains the missing key name.
import pytest def test_missing_key(): with pytest.raises([1]) as excinfo: data = {'a': 1} value = data[[2]] assert [3] in str(excinfo.value)
The test expects a KeyError when accessing a missing key 'b', and checks the error message includes 'b' to confirm the missing key.