0
0
PyTesttesting~5 mins

Marker registration in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a marker in pytest?
A marker is a label you can add to tests to organize, select, or skip them during test runs.
Click to reveal answer
beginner
Why do you need to register markers in pytest?
To avoid warnings and to document custom markers so pytest knows they are valid and how to use them.
Click to reveal answer
beginner
Where do you register custom markers in pytest?
In the pytest.ini file under the [pytest] section using the markers option.
Click to reveal answer
beginner
Example of registering a custom marker named 'slow' in pytest.ini?
Add this line in pytest.ini: markers = slow: marks tests as slow to run
Click to reveal answer
beginner
How do you run only tests marked with a registered marker 'slow'?
Use the command: pytest -m slow
Click to reveal answer
What happens if you use a custom marker without registering it in pytest.ini?
ATests with that marker fail automatically.
BPytest ignores the marker silently.
CPytest registers the marker automatically.
DPytest shows a warning about unknown marker.
Where do you add marker registration in a pytest project?
AIn pytest.ini file under [pytest] section.
BIn the test file as a comment.
CIn the Python test function docstring.
DIn the command line only.
How do you mark a test as 'slow' in pytest after registering the marker?
AName the test function slow_test().
BAdd @pytest.mark.slow above the test function.
CAdd slow=True in the test function parameters.
DUse a comment # slow inside the test.
What command runs only tests marked with 'slow'?
Apytest -m slow
Bpytest --only slow
Cpytest --mark slow
Dpytest --filter slow
Which section header is used in pytest.ini to register markers?
A[markers]
B[test_markers]
C[pytest]
D[custom]
Explain how to create and register a custom marker in pytest.
Think about configuration and usage steps.
You got /5 concepts.
    Describe how to run tests selectively using markers in pytest.
    Focus on command line usage.
    You got /4 concepts.