Bird
0
0

How can you skip a pytest test only if a feature flag is disabled, providing the reason "Feature disabled"?

hard🚀 Application Q8 of 15
PyTest - Markers
How can you skip a pytest test only if a feature flag is disabled, providing the reason "Feature disabled"?
A@pytest.mark.skip(reason="Feature disabled") if not feature_enabled else None
B@pytest.mark.skipif(not feature_enabled, reason="Feature disabled")
CUse <code>pytest.skip("Feature disabled")</code> inside the test unconditionally
DUse <code>@pytest.mark.skipif(feature_enabled, reason="Feature disabled")</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditional skipping

    Use @pytest.mark.skipif(condition, reason=...) to skip based on a condition.
  2. Step 2: Condition logic

    Skip if the feature is disabled, so condition is not feature_enabled.
  3. Final Answer:

    @pytest.mark.skipif(not feature_enabled, reason="Feature disabled") -> Option B
  4. Quick Check:

    Use skipif with condition and reason [OK]
Quick Trick: Use skipif with condition and reason [OK]
Common Mistakes:
MISTAKES
  • Using skip instead of skipif for conditions
  • Reversing condition logic
  • Calling skip inside test unconditionally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes