Testing with Python
Pytest recipes
Parametrizing fixtures and test functions
Reference: pytest parametrize documentation
import pytest
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
("6*9", 54),
])
def test_eval(test_input, expected):
assert eval(test_input) == expected
Fixtures
import pytest
@pytest.fixture
def bridgekeeper():
return {"colour": "blue"}
def test_answer(bridgekeeper):
assert bridgekeeper["colour"] == "blue"
A fixture is requested by naming it as a test argument; pytest builds it fresh for each test.