# How We Replaced Dozens of Test Fixtures With One Simple Function

DevFeed: [How We Replaced Dozens of Test Fixtures With One Simple Function](<https://devfeed.tech/articles/how-we-replaced-dozens-of-test-fixtures-with-one-simple-function-33913.md>)

Original publisher: [Read original article](<https://hakibenita.com/how-we-replaced-dozens-of-test-fixtures-with-one-simple-function>)

Author: Haki Benita

Published: 2017-08-15T21:00:00Z

Content type: tutorial

Language: en

Sources: [Haki Benita](<https://devfeed.tech/sources/haki-benita.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [feature flags](<https://devfeed.tech/topics/feature-flags.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [context](<https://devfeed.tech/tags/context.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [django](<https://devfeed.tech/tags/django.md>), [feature-flags](<https://devfeed.tech/tags/feature-flags.md>), [functions](<https://devfeed.tech/tags/functions.md>), [python](<https://devfeed.tech/tags/python.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

This article explains how replacing extensive test fixtures with a reusable context-manager utility simplified tests for feature flags and other objects. The approach saves original values, applies temporary changes, and restores them after each test, while also enabling setup to move from the test level to the class level in some cases.

## Source excerpt

We had a large codebase and a lot of tests. Unfortunately, a lot of our tests were a relic from when we were using fixtures extensively. In this article, we describe a different approach that reduced the number of fixtures we maintain.