Bird
0
0

Given this pytest code, what will be the output when running test_sum?

medium📝 Predict Output Q4 of 15
PyTest - Fixtures
Given this pytest code, what will be the output when running test_sum?
import pytest

@pytest.fixture
def numbers():
    return [1, 2, 3]

def test_sum(numbers):
    assert sum(numbers) == 6
ATest fails with assertion error
BTest passes successfully
CSyntax error due to fixture usage
DTest is skipped automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture injection

    The fixture 'numbers' returns [1, 2, 3], which is passed to test_sum as argument.
  2. Step 2: Evaluate the assertion

    sum([1, 2, 3]) equals 6, so the assertion passes.
  3. Final Answer:

    Test passes successfully -> Option B
  4. Quick Check:

    Fixture provides data, assertion true = Pass [OK]
Quick Trick: Fixture returns data used in test assertions [OK]
Common Mistakes:
MISTAKES
  • Assuming fixture causes syntax error
  • Thinking test fails due to wrong sum
  • Believing test is skipped without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes