Bird
0
0

Given the following pytest code, which tests will run when executing pytest -m "critical"?

medium📝 Predict Output Q4 of 15
PyTest - Test Organization
Given the following pytest code, which tests will run when executing pytest -m "critical"? ```python import pytest @pytest.mark.critical def test_login(): assert True @pytest.mark.regular def test_logout(): assert True def test_profile(): assert True ```
ANo tests will run
BBoth <code>test_login</code> and <code>test_logout</code> will run
CAll three tests will run
DOnly <code>test_login</code> will run
Step-by-Step Solution
Solution:
  1. Step 1: Understand marker filtering

    Using pytest -m "critical" runs tests marked with 'critical'.
  2. Step 2: Identify marked tests

    Only test_login is marked with @pytest.mark.critical.
  3. Step 3: Tests without marker or with different marker are excluded

    test_logout and test_profile won't run.
  4. Final Answer:

    Only test_login will run -> Option D
  5. Quick Check:

    Marker filter runs only matching marked tests [OK]
Quick Trick: -m runs only tests with matching marker [OK]
Common Mistakes:
MISTAKES
  • Assuming unmarked tests run with marker filter
  • Confusing multiple markers with OR logic
  • Expecting all tests to run without markers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes