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?
✗ Incorrect
The simple command
pytest runs all tests it finds in the current directory and subdirectories.How do you run tests in a specific file named
test_math.py?✗ Incorrect
Use
pytest test_math.py to run tests only in that file.What does the
-v option do when running pytest?✗ Incorrect
The
-v option makes pytest show detailed info about each test run.Which pytest option reruns only the tests that failed last time?
✗ Incorrect
The
--lf or --last-failed option reruns only previously failed tests.How do you run tests with names containing 'user' using pytest?
✗ Incorrect
The
-k option filters tests by name matching the given expression.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.