Complete the code to test if a ValueError is raised.
import pytest def test_value_error(): with pytest.raises([1]): int('abc')
The pytest.raises() function expects the exception type to check. Here, int('abc') raises a ValueError.
Complete the code to test if a ZeroDivisionError is raised.
import pytest def test_zero_division(): with pytest.raises([1]): result = 10 / 0
Dividing by zero raises a ZeroDivisionError. The test checks for this specific exception.
Fix the error in the test to correctly check for multiple exceptions.
import pytest def test_multiple_exceptions(): with pytest.raises(([1])): int('abc') result = 10 / 0
To test multiple exceptions, pass a tuple of exception types without brackets or quotes around the types.
Fill both blanks to test if either KeyError or IndexError is raised.
import pytest def test_key_or_index_error(): with pytest.raises(([1], [2])): d = {} _ = d['missing_key']
The test checks for either KeyError or IndexError. Both are valid exceptions to catch here.
Fill all three blanks to test if either AttributeError, TypeError, or ValueError is raised.
import pytest def test_multiple_exceptions_complex(): with pytest.raises(([1], [2], [3])): obj = None obj.some_method()
This test expects one of three exceptions: AttributeError if the method does not exist, TypeError if the call is invalid, or ValueError for invalid values.