Introduction to Testing in Python
Alexander Levin
Data Scientist
Imagine preparation for a picnic:
Fixtures help:
Assume we have:
list variable named datadata = [0, 1, 1, 2, 3, 5, 8, 13, 21]And we want to test, that:
5 and 21import pytest
# Fixture decorator
@pytest.fixture
# Fixture for data initialization
def data():
return [0, 1, 1, 2, 3, 5, 8, 13, 21]
def test_list(data):
assert len(data) == 9
assert 5 in data
assert 21 in data
Output of the example:

To use the fixture we have to do the following:
@pytest.fixture decoratorWe learned about testing fixtures:
listpytest fixture by declaring @pytest.fixtureIntroduction to Testing in Python