0
0
PyTesttesting~5 mins

pytest-timeout for time limits - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the pytest-timeout plugin?
pytest-timeout is used to set a maximum time limit for test functions. If a test runs longer than the specified time, it is stopped and marked as failed.
Click to reveal answer
beginner
How do you apply a timeout of 5 seconds to a single test function using pytest-timeout?
You add the decorator @pytest.mark.timeout(5) above the test function to limit its execution time to 5 seconds.
Click to reveal answer
beginner
What happens if a test exceeds the timeout set by pytest-timeout?
The test is interrupted and marked as failed with a timeout error, helping to catch tests that hang or run too long.
Click to reveal answer
intermediate
How can you set a global timeout for all tests in pytest using pytest-timeout?
You can add timeout = 5 in the pytest.ini configuration file under the [pytest] section to apply a 5-second timeout to all tests.
Click to reveal answer
beginner
Why is it useful to set time limits on tests?
Setting time limits helps detect infinite loops, slow tests, or deadlocks early, improving test suite reliability and speed.
Click to reveal answer
Which pytest-timeout decorator sets a 10-second limit on a test?
A@pytest.timeout(10)
B@pytest.set_timeout(10)
C@timeout(10)
D@pytest.mark.timeout(10)
What happens when a test exceeds the timeout set by pytest-timeout?
ATest is marked as failed
BTest is skipped
CTest continues running
DTest is retried automatically
Where do you configure a global timeout for all tests using pytest-timeout?
AIn setup.py
BIn the test function decorator
CIn pytest.ini file
DIn requirements.txt
Which of these is NOT a benefit of using pytest-timeout?
ADetecting infinite loops
BAutomatically fixing test bugs
CPreventing hanging tests
DImproving test speed
How do you install pytest-timeout?
Apip install pytest-timeout
Bpip install timeout-pytest
Cpip install pytest-time
Dpip install timeout
Explain how to set a timeout for a single test and what happens if the test exceeds this timeout.
Think about the decorator and test failure behavior.
You got /4 concepts.
    Describe how to configure a global timeout for all tests in pytest using pytest-timeout.
    Consider pytest configuration files.
    You got /4 concepts.