Bird
0
0

Given the code below, what will be the test result when run on Linux?

medium📝 Predict Output Q5 of 15
PyTest - Parametrize
Given the code below, what will be the test result when run on Linux?
import sys
import pytest

@pytest.mark.parametrize('val', [pytest.param('a', marks=pytest.mark.skipif(sys.platform != 'linux', reason='Linux only')), 'b'])
def test_val(val):
    assert val in ['a', 'b']
ABoth tests run and pass
BOnly test with val='a' runs and passes
COnly test with val='b' runs and passes
DBoth tests are skipped
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate skipif condition for 'a'

    Condition is sys.platform != 'linux'. On Linux, this is False, so 'a' test runs.
  2. Step 2: Check test with 'b'

    'b' has no skip marks, so it runs normally.
  3. Final Answer:

    Both tests run and pass -> Option A
  4. Quick Check:

    Skip if not Linux means 'a' runs on Linux [OK]
Quick Trick: Check platform condition carefully to know which params run [OK]
Common Mistakes:
MISTAKES
  • Assuming 'a' is skipped on Linux
  • Ignoring unmarked parameters
  • Misreading platform string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes