Complete the code to check if a ZeroDivisionError is raised.
import pytest def test_divide_by_zero(): with pytest.[1](ZeroDivisionError): x = 1 / 0
The pytest.raises context manager is used to check if the specified exception is raised inside the block.
Complete the code to check if a ValueError is raised when converting a string to int.
import pytest def test_invalid_int(): with pytest.[1](ValueError): int('abc')
Use pytest.raises to verify that int('abc') raises a ValueError.
Fix the error in the code to properly check for a KeyError.
import pytest def test_key_error(): with pytest.[1](KeyError): d = {'a': 1} value = d['b']
The correct context manager to check for exceptions in pytest is raises. Using any other word causes an error.
Fill both blanks to check if a TypeError is raised and capture the exception as 'exc'.
import pytest def test_type_error(): with pytest.[1](TypeError) as [2]: int(None)
Use raises as the context manager and as exc to capture the exception object.
Fill all three blanks to check for an IndexError, capture it as 'e', and assert the error message contains 'list index out of range'.
import pytest def test_index_error(): with pytest.[1](IndexError) as [2]: lst = [] _ = lst[0] assert '[3]' in str(e.value)
Use raises to check the exception, capture it as e, and assert the expected message is in str(e.value).