Bird
0
0

You have a fixture defined in conftest.py as follows:

medium📝 Debug Q14 of 15
PyTest - Fixtures
You have a fixture defined in conftest.py as follows:
import pytest

@pytest.fixture
def data():
    return [1, 2, 3]
In your test file, you wrote:
def test_sum(data):
    assert sum(data) == 10
What is the problem and how to fix it?
AAssertion is wrong; sum([1,2,3]) is 6, so change 10 to 6
BFixture not imported; add <code>from conftest import data</code>
CFixture must be a class, not a function
Dsum() cannot be used on lists
Step-by-Step Solution
Solution:
  1. Step 1: Check the fixture return value

    The fixture data returns the list [1, 2, 3].
  2. Step 2: Calculate the sum and compare with assertion

    sum([1, 2, 3]) equals 6, but the test asserts it equals 10, which is incorrect.
  3. Final Answer:

    Assertion is wrong; sum([1,2,3]) is 6, so change 10 to 6 -> Option A
  4. Quick Check:

    sum([1,2,3]) = 6, fix assertion [OK]
Quick Trick: Verify expected values match fixture data [OK]
Common Mistakes:
MISTAKES
  • Thinking fixture must be imported explicitly
  • Assuming sum() can't handle lists
  • Changing fixture type unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes