Bird
0
0

You wrote this conftest.py fixture:

medium📝 Debug Q14 of 15
PyTest - Test Organization
You wrote this conftest.py fixture:
import pytest

@pytest.fixture
def data():
    return [1, 2, 3]
But your test fails with an error: fixture 'data' not found. What is the likely cause?
AThe test function does not accept <code>data</code> as a parameter
BThe fixture function is missing the <code>return</code> statement
CThe fixture is defined with a wrong decorator like <code>@pytest.test</code>
DThe <code>conftest.py</code> file is not in the same or parent directory of the test file
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest fixture discovery

    Pytest finds conftest.py files in the test directory or its parents. If conftest.py is elsewhere, fixtures won't be found.
  2. Step 2: Analyze other options

    Options A, B, and D would cause different errors or test failures, but not 'fixture not found'.
  3. Final Answer:

    The conftest.py file is not in the same or parent directory of the test file -> Option D
  4. Quick Check:

    Fixture not found means wrong file location = C [OK]
Quick Trick: Check conftest.py location relative to tests [OK]
Common Mistakes:
MISTAKES
  • Ignoring file placement rules
  • Assuming missing return causes fixture not found
  • Not passing fixture as test parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes