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.
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
Updated