Bird
0
0

Identify the issue in this pytest test code:

medium📝 Debug Q7 of 15
PyTest - Fixtures
Identify the issue in this pytest test code:
import pytest

@pytest.fixture
def number():
    return 10

def test_number():
    assert number == 10
AThe fixture decorator is missing
BThe fixture should return a string, not an integer
CThe fixture 'number' is not passed as a parameter to the test function
DThe test function should be named 'test_fixture'
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture usage

    Fixtures must be accepted as parameters in test functions to be used.
  2. Step 2: Analyze test function

    Here, 'number' fixture is defined but not passed to 'test_number'.
  3. Final Answer:

    The fixture 'number' is not passed as a parameter to the test function -> Option C
  4. Quick Check:

    Pass fixtures as test function arguments [OK]
Quick Trick: Fixtures must be function parameters to be used [OK]
Common Mistakes:
MISTAKES
  • Not passing fixture as argument to test
  • Expecting fixture to be global variable
  • Misnaming test functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes