Fixtures in pytest

Learn about fixtures and how to use them in your tests.

Overview

Fixtures are fixed environment items (usually function inputs and outputs) used in tests. Without fixtures, we do not separate test-case preparation logic from the test itself. Moreover, we’re probably creating almost the same test cases for different tests.

Let’s look at the code below where we add some images to our repository and use the crop_image function to crop an image.

Get hands-on with 1200+ tech skills courses.