Bird
0
0

Find the bug in this fixture factory usage: ```python @pytest.fixture def factory(): def inner(x): return x * 2 return inner def test_double(factory): assert factory == 4 ```

medium📝 Debug Q7 of 15
PyTest - Fixtures
Find the bug in this fixture factory usage: ```python @pytest.fixture def factory(): def inner(x): return x * 2 return inner def test_double(factory): assert factory == 4 ```
AThe fixture factory is missing the @pytest.mark.usefixtures decorator
BThe test should not use the fixture as an argument
CThe inner function should not accept parameters
DThe test compares the function object to an integer instead of calling it
Step-by-Step Solution
Solution:
  1. Step 1: Analyze test assertion

    The test compares factory (a function) directly to 4, which is incorrect.
  2. Step 2: Correct test usage

    The test should call factory with an argument, e.g., factory(2) == 4.
  3. Final Answer:

    The test compares the function object to an integer instead of calling it -> Option D
  4. Quick Check:

    Call fixture function before asserting [OK]
Quick Trick: Call fixture function before comparing results [OK]
Common Mistakes:
MISTAKES
  • Comparing function object to value
  • Missing parentheses to call function
  • Misusing fixture decorators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes