0
0
PyTesttesting~5 mins

Registering markers in pytest.ini - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of registering markers in pytest.ini?
Registering markers in pytest.ini helps pytest recognize custom markers, avoid warnings, and organize tests by categories or features.
Click to reveal answer
beginner
How do you register a custom marker named slow in pytest.ini?
Add the following under the [pytest] section:<br>
[pytest]
markers =
    slow: marks tests as slow to run
Click to reveal answer
intermediate
Why should you register markers instead of just using them directly in test code?
If markers are not registered, pytest shows warnings during test runs. Registering markers documents their purpose and improves test clarity.
Click to reveal answer
intermediate
What is the syntax to register multiple markers in pytest.ini?
List each marker on a new line under the markers key:<br>
[pytest]
markers =
    slow: marks tests as slow
    smoke: marks smoke tests
    api: marks API tests
Click to reveal answer
beginner
Where should the pytest.ini file be placed in your project?
Place pytest.ini in the root folder of your project so pytest can find it automatically when running tests.
Click to reveal answer
What happens if you use a custom marker in pytest without registering it in pytest.ini?
APytest runs tests normally but shows a warning about unknown markers.
BPytest ignores the marker and skips the test.
CPytest throws an error and stops running tests.
DPytest automatically registers the marker.
How do you define a marker description in pytest.ini?
A[markers] marker_name = description
Bmarker_name = description of the marker
Cmarkers = marker_name: description of the marker
Dmarkers: marker_name - description
Where in the pytest.ini file do you register markers?
AUnder the [test] section
BUnder the [markers] section
CAt the top of the file without a section
DUnder the [pytest] section
Which of these is a valid marker registration in pytest.ini?
A[pytest] markers = database: marks tests that use the database
B[markers] database = marks tests that use the database
Cmarkers: database - marks tests that use the database
D[pytest] database = marks tests that use the database
Why is it helpful to register markers in pytest.ini?
ATo speed up test execution
BTo avoid warnings and document test categories
CTo automatically generate test reports
DTo disable tests permanently
Explain how to register a custom marker in pytest.ini and why it is important.
Think about the file structure and the syntax needed to tell pytest about your marker.
You got /6 concepts.
    Describe the consequences of not registering markers in pytest.ini when using them in your tests.
    Consider what pytest does when it sees a marker it does not recognize.
    You got /4 concepts.