# Test Fixture

*noun*

say it: **“TEST FIKS-cher”** **/tɛst ˈfɪkstʃər/**

Setup a test needs, such as sample data or a temporary file, written once and shared by many tests; in pytest, a function marked @pytest.fixture.

## What is a **test fixture**?

A **test fixture** sets up what a test needs, like sample data, so many tests can share it. In `pytest` it's a function marked `@pytest.fixture`.

```python
import pytest

@pytest.fixture
def cart():
    return ["book", "pen"]

def test_cart_has_two_items(cart):
    assert len(cart) == 2
```

## In a sentence

- “The cart **test fixture** gave each test a fresh list of two items.”
- “Every test that names sample_orders as a parameter gets the **test fixture**'s data.”

Level: Journeyman · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=3)

Updated: November 19, 2026

## In other subjects

- [Test Fixture in C#](https://www.ask-codey.com/glossary/test-fixture-c-sharp)
- [Test Fixture in Java](https://www.ask-codey.com/glossary/test-fixture-java)

Source: https://www.ask-codey.com/glossary/test-fixture
