0
0
PyTesttesting~5 mins

Running tests (pytest command) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the basic command to run tests using pytest?
The basic command is pytest. Running this in the terminal will discover and run all test files and functions following pytest naming conventions.
Click to reveal answer
beginner
How do you run a specific test file with pytest?
Use pytest <filename>.py to run tests only in that file. For example, pytest test_example.py runs tests in test_example.py.
Click to reveal answer
beginner
What option shows detailed output for each test when running pytest?
Use pytest -v to run tests in verbose mode. It shows each test name and its pass/fail status clearly.
Click to reveal answer
intermediate
How can you run only tests that failed in the last pytest run?
Use pytest --lf (or --last-failed) to rerun only the tests that failed previously. This helps focus on fixing errors quickly.
Click to reveal answer
intermediate
What does the command pytest -k "expression" do?
It runs only tests whose names match the given expression. For example, pytest -k "login" runs tests with 'login' in their names.
Click to reveal answer
Which command runs all tests in the current directory using pytest?
Apytest
Bpytest run
Cpytest all
Dpytest start
How do you run tests in a specific file named test_math.py?
Apytest run test_math.py
Bpytest -f test_math.py
Cpytest test_math.py
Dpytest -file test_math.py
What does the -v option do when running pytest?
ARuns tests very fast
BRuns tests in verbose mode showing detailed info
CValidates test syntax only
DVerifies pytest installation
Which pytest option reruns only the tests that failed last time?
A--fail-last
B--failed-only
C--rerun-fail
D--lf
How do you run tests with names containing 'user' using pytest?
Apytest -k "user"
Bpytest --name user
Cpytest --filter user
Dpytest -f user
Explain how to run all tests and how to run tests from a specific file using pytest.
Think about the simplest command and how to specify a file.
You got /3 concepts.
    Describe how to rerun only failed tests and how to run tests selectively by name using pytest.
    Focus on options that help save time during test runs.
    You got /3 concepts.