Hint: Use [markers] section and '=' to register markers [OK]
Common Mistakes:
Using [pytest] instead of [markers]
Using colon ':' instead of '='
Listing markers without description
3. Given this pytest.ini content:
[markers]
api = marks tests as api tests
slow = marks tests as slow
What happens if you run pytest -m slow?
medium
A. Only tests marked with @pytest.mark.slow will run
B. All tests will run except those marked slow
C. Tests marked with @pytest.mark.api will run
D. Pytest will show a warning about unknown marker
Solution
Step 1: Understand marker filtering with -m option
The -m option runs tests matching the given marker name.
Step 2: Match marker name with registered markers
Since slow is registered and used, pytest -m slow runs only tests marked with @pytest.mark.slow.
Final Answer:
Only tests marked with @pytest.mark.slow will run -> Option A
Quick Check:
pytest -m marker = runs tests with that marker [OK]
Hint: pytest -m runs tests with the named marker only [OK]
Common Mistakes:
Thinking -m excludes tests with the marker
Confusing marker names
Expecting warnings when marker is registered
4. You added this to your pytest.ini:
[markers]
fast marks tests as fast
But when running tests, pytest shows a warning about unknown marker 'fast'. What is the problem?
medium
A. Marker name 'fast' is reserved and cannot be used
B. Markers section header is misspelled
C. Missing '=' sign between marker name and description
D. pytest.ini file is in the wrong directory
Solution
Step 1: Check marker registration syntax
The marker line must have an equals sign = between the marker name and its description.
Step 2: Identify missing '=' causing warning
Here, fast marks tests as fast lacks '=', so pytest treats 'fast' as unknown marker.
Final Answer:
Missing '=' sign between marker name and description -> Option C
Quick Check:
Marker line needs '=' sign [OK]
Hint: Always use '=' between marker and description [OK]
Common Mistakes:
Forgetting '=' sign
Misspelling [markers] header
Placing pytest.ini in wrong folder
5. You want to register two markers in pytest.ini: db for database tests and ui for user interface tests. Which pytest.ini content correctly registers both markers?
hard
A. [markers]
db = marks tests as database tests
ui = marks tests as user interface tests
B. [pytest]
markers = db, ui
C. [markers]
db: marks database tests
ui: marks UI tests
D. [pytest]
db = database tests
ui = UI tests
Solution
Step 1: Confirm correct section header
Markers must be under the [markers] section, not [pytest].
Step 2: Verify correct syntax for each marker
Each marker line uses = with a description, e.g., db = marks tests as database tests.
Step 3: Check all markers are listed separately
Both db and ui markers are listed on separate lines with descriptions.
Final Answer:
[markers]
db = marks tests as database tests
ui = marks tests as user interface tests -> Option A
Quick Check:
Separate lines under [markers] with '=' for each marker [OK]
Hint: List each marker under [markers] with '=' and description [OK]
Common Mistakes:
Using [pytest] instead of [markers]
Using commas to list markers
Using ':' instead of '='
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.