Bird
0
0

Given the following conftest.py fixture and test file, what will be the output when running pytest?

medium📝 Predict Output Q13 of 15
PyTest - Fixtures
Given the following conftest.py fixture and test file, what will be the output when running pytest?
-- conftest.py --
import pytest

@pytest.fixture
def number():
    return 5

-- test_sample.py --

def test_double(number):
    assert number * 2 == 10

def test_triple(number):
    assert number * 3 == 15
ABoth tests pass
BBoth tests fail
Ctest_double passes, test_triple fails
Dtest_double fails, test_triple passes
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture usage

    The fixture number returns 5 and is shared automatically via conftest.py.
  2. Step 2: Evaluate test assertions

    test_double checks 5*2 == 10 (True), test_triple checks 5*3 == 15 (True). Both assertions are correct.
  3. Final Answer:

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

    Fixture returns 5, assertions match [OK]
Quick Trick: Check fixture value and test assertions carefully [OK]
Common Mistakes:
MISTAKES
  • Assuming fixture is not shared without import
  • Miscalculating expected assertion values
  • Confusing test pass/fail logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes