Bird
0
0

In pytest, what happens immediately after the yield statement inside a fixture?

easy🧠 Conceptual Q1 of 15
PyTest - Fixtures
In pytest, what happens immediately after the yield statement inside a fixture?
AThe test function using the fixture is executed
BThe fixture setup code runs again
CThe fixture is destroyed before the test runs
DThe fixture skips the test execution
Step-by-Step Solution
Solution:
  1. Step 1: Understand yield in fixture

    The yield statement splits the fixture into setup (before yield) and teardown (after yield).
  2. Step 2: Execution flow

    After the setup code runs and yield is reached, pytest runs the test function that uses the fixture.
  3. Final Answer:

    The test function using the fixture is executed -> Option A
  4. Quick Check:

    Yield pauses fixture, runs test, then resumes teardown [OK]
Quick Trick: Yield pauses fixture, runs test, then resumes teardown [OK]
Common Mistakes:
MISTAKES
  • Thinking teardown runs before the test
  • Assuming fixture runs twice
  • Believing yield skips test execution

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes