0
0
PyTesttesting~5 mins

Custom markers in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a custom marker in pytest?
A custom marker is a label you create to tag tests for special handling, like grouping or skipping them during test runs.
Click to reveal answer
beginner
How do you define a custom marker in pytest?
You define a custom marker by adding it to the pytest.ini file under the [pytest] section using the markers option.
Click to reveal answer
beginner
How do you apply a custom marker to a test function?
Use the @pytest.mark.<marker_name> decorator above the test function to apply the custom marker.
Click to reveal answer
beginner
What command runs only tests with a specific custom marker?
Use pytest -m '<marker_name>' to run only tests tagged with that custom marker.
Click to reveal answer
intermediate
Why should you register custom markers in pytest.ini?
Registering markers avoids warnings and helps pytest recognize your custom tags properly.
Click to reveal answer
How do you mark a test with a custom marker named 'slow'?
A@pytest.mark.slow
B@slow
Cmark('slow')
Dpytest.mark('slow')
Where do you register custom markers to avoid warnings?
Atest file header
Bconftest.py
Csetup.py
Dpytest.ini
What does the command 'pytest -m slow' do?
ASkips tests marked with 'slow'
BRuns only tests marked with 'slow'
CRuns all tests except those marked 'slow'
DRuns tests with names containing 'slow'
What happens if you use a custom marker without registering it?
ATests run but marker is ignored silently
BTests fail to run
CPytest shows a warning about unknown markers
DPytest crashes
Which file is best for defining markers used across many test files?
Apytest.ini
Btest_example.py
Crequirements.txt
DREADME.md
Explain how to create and use a custom marker in pytest.
Think about registration, tagging, and running tests.
You got /3 concepts.
    Why is it important to register custom markers in pytest.ini?
    Consider what happens if you don't register.
    You got /3 concepts.