Bird
0
0

What will be the output of the following pytest code when running test_add?

medium📝 Predict Output Q4 of 15
PyTest - Fixtures
What will be the output of the following pytest code when running test_add?
import pytest

@pytest.fixture
def number():
    return 5

def test_add(number):
    assert number + 3 == 8
ATest passes successfully
BTest fails with assertion error
CSyntax error due to fixture usage
DRuntime error: fixture not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture execution

    The fixture 'number' returns 5, which is passed to the test function as argument.
  2. Step 2: Evaluate the assertion

    The test asserts 5 + 3 == 8, which is true, so the test passes.
  3. Final Answer:

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

    Fixture value used correctly = test passes [OK]
Quick Trick: Fixture return value is passed to test argument [OK]
Common Mistakes:
MISTAKES
  • Assuming fixture must be called inside test
  • Expecting test to fail due to wrong assertion
  • Thinking fixture causes syntax or runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes