The -m slow option runs only tests marked with @pytest.mark.slow.
Step 2: Identify marked tests
test_example is marked with @pytest.mark.slow, test_fast is not.
Final Answer:
Only test_example runs and passes -> Option C
Quick Check:
Run with -m slow = only slow tests run [OK]
Hint: -m runs only tests with matching marker [OK]
Common Mistakes:
Assuming all tests run with -m option
Confusing marker name with test function name
Ignoring marker registration effect
4. You added a custom marker database to your tests but pytest shows a warning: PytestUnknownMarkWarning. What is the most likely cause and how to fix it?
medium
A. You must run pytest with --disable-warnings to hide the message
B. You forgot to register the database marker in pytest.ini; add it under [pytest] markers
C. You need to rename the marker to db to avoid warnings
D. You used @pytest.mark.database incorrectly; remove the decorator
Solution
Step 1: Identify cause of PytestUnknownMarkWarning
This warning appears when a custom marker is used but not registered in pytest.ini.
Step 2: Fix by registering marker
Add database marker under the [pytest] section in pytest.ini to register it and remove the warning.
Final Answer:
You forgot to register the database marker in pytest.ini; add it under [pytest] markers -> Option B
Quick Check:
Warning = missing marker registration [OK]
Hint: Register all custom markers in pytest.ini to avoid warnings [OK]
Common Mistakes:
Ignoring the warning and continuing
Removing marker decorator instead of registering
Trying to rename marker instead of registering
5. You want to run tests marked as api but skip those marked as slow. Your pytest.ini contains:
[pytest]
markers =
api: marks API tests
slow: marks slow tests
Which command correctly runs only api tests excluding slow tests?
hard
A. pytest -m "not api and slow"
B. pytest -m "api or slow"
C. pytest -m "slow and not api"
D. pytest -m "api and not slow"
Solution
Step 1: Understand marker expressions with -m
The -m option accepts boolean expressions combining markers using and, or, and not.
Step 2: Build expression for api tests excluding slow
We want tests marked api but not slow, so expression is api and not slow.
Final Answer:
pytest -m "api and not slow" -> Option D
Quick Check:
Run api tests excluding slow = pytest -m "api and not slow" [OK]
Hint: Use -m "api and not slow" to include/exclude markers [OK]
Common Mistakes:
Using 'or' instead of 'and not' excludes wrong tests
Misplacing 'not' operator
Confusing marker names in expression
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.