Complete the code to set a timeout of 5 seconds for the test function.
import pytest @pytest.mark.timeout([1]) def test_example(): assert 1 + 1 == 2
The @pytest.mark.timeout(5) decorator sets a 5-second timeout for the test.
Complete the code to apply a timeout of 3 seconds using a pytest fixture.
import pytest @pytest.fixture(autouse=True) def set_timeout(): pytest.timeout = [1] def test_fast(): assert True
Setting pytest.timeout = 3 inside an autouse fixture applies a 3-second timeout to tests.
Fix the error in the code to correctly apply a 2-second timeout to the test.
import pytest @pytest.mark.timeout([1]) def test_slow(): import time time.sleep(3) assert True
The timeout must be less than the sleep time to trigger a timeout failure. Using 2 seconds works.
Fill both blanks to set a timeout of 4 seconds and handle the timeout exception in the test.
import pytest from pytest_timeout import TimeoutException @pytest.mark.timeout([1]) def test_timeout_handling(): try: import time time.sleep(5) except [2]: assert True
Use @pytest.mark.timeout(4) to set timeout and catch TimeoutException to handle it.
Fill all three blanks to apply a 6-second timeout, skip the test if it times out, and import the correct decorator.
import pytest from pytest_timeout import [1] @[2].timeout([3]) def test_skip_on_timeout(): import time time.sleep(10) assert True
Import mark from pytest_timeout and use @mark.timeout(6) to set a 6-second timeout.