0
0
PyTesttesting~5 mins

Command-line options in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of command-line options in pytest?
Command-line options in pytest allow you to customize test runs, such as selecting tests, setting verbosity, or enabling features without changing the code.
Click to reveal answer
beginner
How do you run pytest with increased verbosity using command-line options?
Use the -v or --verbose option to increase verbosity, showing more details about each test run.
Click to reveal answer
intermediate
What does the -k option do in pytest?
The -k option lets you run tests that match a specific expression or substring in their names, helping to select tests easily.
Click to reveal answer
intermediate
Explain the use of the --maxfail option in pytest.
The --maxfail=N option stops the test run after N failures, which helps save time by not running all tests if many fail.
Click to reveal answer
beginner
How can you run tests from a specific file using pytest command-line options?
You can specify the test file path directly after the pytest command, for example: pytest tests/test_example.py to run tests only from that file.
Click to reveal answer
Which pytest option runs tests with detailed output?
A--maxfail
B-v
C-q
D-k
What does the -k option do in pytest?
ARuns tests matching a name pattern
BStops after first failure
CRuns tests quietly
DSets maximum failures allowed
How do you stop pytest after 3 test failures?
A-v 3
B--failmax=3
C-k 3
D--maxfail=3
Which command runs tests only from a specific file?
Apytest tests/test_file.py
Bpytest -k test_file
Cpytest --maxfail=1
Dpytest -v
What does the -q option do in pytest?
AFilters tests by name
BRuns tests with detailed output
CRuns tests quietly with less output
DStops after first failure
Describe how you can use pytest command-line options to select and control test execution.
Think about filtering tests and controlling output.
You got /4 concepts.
    Explain why command-line options are useful when running tests with pytest.
    Consider flexibility and efficiency.
    You got /4 concepts.