Python Quest

Track 13 · Lesson 7 of 12

Fixtures, setup and test isolation

Share setup between tests with pytest fixtures, clean up with yield, use temporary files, and keep every test independent.

About 45 minIntermediate3 exercises

You will be able to

  • Explain why tests must not depend on each other or on shared mutable state
  • Write a pytest fixture and request it from tests by parameter name
  • Use yield in a fixture to run cleanup code after each test
  • Test file-handling code with the built-in tmp_path fixture

Included with a Formula Quest membership

It has 3 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.