0
0
PyTesttesting~20 mins

Command-line options in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Command-line Options Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pytest with verbose option
What is the output behavior when running pytest -v on a test file with 3 passing tests?
PyTest
def test_one():
    assert 1 == 1

def test_two():
    assert 2 == 2

def test_three():
    assert 3 == 3
Apytest shows only a summary line with dots for each test
Bpytest runs tests silently without showing any test names
Cpytest stops after the first test and shows only one test result
Dpytest shows detailed test names and statuses for all 3 tests
Attempts:
2 left
💡 Hint
The -v option stands for verbose output.
assertion
intermediate
2:00remaining
Correct assertion for exit code with pytest --maxfail=1
You run pytest --maxfail=1 on a test suite with multiple failing tests. Which assertion correctly checks that pytest stopped after the first failure?
PyTest
import subprocess
result = subprocess.run(['pytest', '--maxfail=1'], capture_output=True, text=True)
exit_code = result.returncode
Aassert exit_code == 1 # pytest exits with 1 on failure
Bassert exit_code == None # pytest does not return exit code
Cassert exit_code > 1 # pytest exits with code >1 on maxfail
Dassert exit_code == 0 # pytest exits with 0 even if tests fail
Attempts:
2 left
💡 Hint
pytest returns 0 if all tests pass, 1 if any test fails.
locator
advanced
2:00remaining
Best locator for pytest to run tests in a specific directory
You want to run pytest only on tests inside the tests/integration folder. Which command correctly locates and runs those tests?
Apytest --dir=tests/integration
Bpytest -k tests/integration
Cpytest tests/integration
Dpytest -m tests/integration
Attempts:
2 left
💡 Hint
pytest accepts folder paths as positional arguments to run tests there.
🔧 Debug
advanced
2:00remaining
Identify the error in pytest command usage
Which pytest command will cause an error when trying to run tests with keyword expression login and not slow?
Apytest -k login and not slow
Bpytest -k 'login and not slow'
Cpytest -k "login and not slow"
Dpytest -k "login and not slow" --maxfail=2
Attempts:
2 left
💡 Hint
Shell interprets unquoted words separately.
framework
expert
2:00remaining
Effect of pytest --tb=short option on test failure output
What is the effect of running pytest with the --tb=short option on the traceback shown for failed tests?
AShows the full detailed traceback with all calls
BShows a shortened traceback with only the last call and error message
CSuppresses all traceback output completely
DShows traceback only for tests marked as slow
Attempts:
2 left
💡 Hint
The --tb option controls traceback verbosity.