Complete the code to assert that a ValueError is raised.
import pytest def test_value_error(): with pytest.[1](ValueError): int('abc')
The pytest.raises context manager is used to check if the specified exception is raised.
Complete the code to check the exception message contains 'invalid literal'.
import pytest def test_error_message(): with pytest.raises(ValueError) as [1]: int('abc') assert 'invalid literal' in [1].value.args[0]
The variable after as captures the exception info object, commonly named excinfo.
Fix the error in the code to properly assert a ZeroDivisionError is raised.
import pytest def test_division(): with pytest.raises([1]): result = 1 / 0
ValueError or other exceptions causes the test to fail.The exception raised by dividing by zero is ZeroDivisionError.
Fill both blanks to assert a KeyError is raised and check its message.
import pytest def test_key_error(): with pytest.[1](KeyError) as [2]: d = {} d['missing']
Use raises as the context manager and excinfo to capture the exception info.
Fill all three blanks to assert a TypeError is raised and check the exception message contains 'unsupported operand'.
import pytest def test_type_error(): with pytest.[1](TypeError) as [2]: result = 'a' + 1 assert '[3]' in [2].value.args[0]
Use raises to catch the exception, excinfo to capture it, and check the message contains unsupported operand.