Recall & Review
beginner
What is a marker in pytest and why is it useful?
A marker is a label you add to tests to group or categorize them. It helps run specific sets of tests easily, like all slow tests or all login tests.
Click to reveal answer
beginner
How do you apply a marker to a test function in pytest?
Use the @pytest.mark.<marker_name> decorator above the test function. For example, @pytest.mark.slow marks the test as slow.
Click to reveal answer
beginner
How can you run only tests with a specific marker using pytest?
Use the command: pytest -m <marker_name>. For example, pytest -m slow runs only tests marked as slow.
Click to reveal answer
intermediate
Why should you register custom markers in pytest's configuration file?
Registering markers in pytest.ini helps avoid warnings and documents the purpose of each marker for better team understanding.
Click to reveal answer
intermediate
Give an example of using markers to separate UI tests from API tests.
Mark UI tests with @pytest.mark.ui and API tests with @pytest.mark.api. Then run them separately using pytest -m ui or pytest -m api.
Click to reveal answer
What does the pytest marker @pytest.mark.smoke indicate?
✗ Incorrect
Markers like 'smoke' label tests as part of a smoke test group to run quick checks.
How do you run tests NOT marked with 'slow' in pytest?
✗ Incorrect
Use pytest -m 'not slow' to exclude tests marked as slow.
Where do you register custom markers to avoid warnings?
✗ Incorrect
Markers should be registered in pytest.ini or tox.ini to document and avoid warnings.
Which decorator syntax correctly marks a test as 'api'?
✗ Incorrect
The correct syntax is @pytest.mark.api.
What is a benefit of using markers in test automation?
✗ Incorrect
Markers help organize tests and run specific groups as needed.
Explain how markers help in organizing and running tests in pytest.
Think about labeling tests to run only certain groups.
You got /4 concepts.
Describe the steps to create and use a custom marker in pytest.
Consider both code and configuration.
You got /3 concepts.