Bird
0
0

Given the pytest command:

medium📝 Predict Output Q5 of 15
PyTest - Markers
Given the pytest command:
pytest -m "database and not slow"
Which tests will be executed?
AAll tests except those marked 'database' or 'slow'
BTests marked with 'database' but not marked with 'slow'
COnly tests marked with both 'database' and 'slow'
DTests marked with 'slow' but not 'database'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the marker expression

    The expression "database and not slow" means tests must have the 'database' marker and must NOT have the 'slow' marker.
  2. Step 2: Understand pytest marker filtering

    Pytest runs tests that satisfy the logical expression given after -m.
  3. Final Answer:

    Tests marked with 'database' but not marked with 'slow' -> Option B
  4. Quick Check:

    Logical AND with NOT excludes 'slow' tests from 'database' tests [OK]
Quick Trick: Use logical operators to include/exclude markers precisely [OK]
Common Mistakes:
MISTAKES
  • Confusing AND with OR in marker expressions
  • Assuming 'not slow' excludes all tests except slow
  • Thinking tests with both markers run

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes