Bird
0
0

Which part of a pytest fixture using yield is executed after the test finishes?

easy🧠 Conceptual Q2 of 15
PyTest - Fixtures
Which part of a pytest fixture using yield is executed after the test finishes?
AThe code before the yield statement
BThe code after the yield statement
CThe entire fixture runs again
DNo code runs after the test
Step-by-Step Solution
Solution:
  1. Step 1: Identify yield position in fixture

    The fixture runs setup code before yield, then pauses to run the test.
  2. Step 2: Teardown code runs after test

    After the test completes, the fixture resumes and runs code after yield for cleanup.
  3. Final Answer:

    The code after the yield statement -> Option B
  4. Quick Check:

    Post-yield code = teardown [OK]
Quick Trick: Teardown code is always after yield [OK]
Common Mistakes:
MISTAKES
  • Thinking setup runs after test
  • Assuming fixture runs twice
  • Ignoring code after yield

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes