C · Testing · intermediate · Week 3–4 · Chapter 8 of 13
Fixtures & parametrization
@pytest.fixture for shared setup. @pytest.mark.parametrize for data-driven tests. conftest.py for shared fixtures.
Path progress56%
Step 1 of 3
Fixtures
Fixture functions provide test data or clients. pytest injects by parameter name.
Example
import pytest
@pytest.fixture
def sample_users():
return [{"username": "a"}, {"username": "b"}]
def test_user_count(sample_users):
assert len(sample_users) == 2Do this now
Create sample_users fixture returning list of dicts. Use in 2 tests.
Was this step clear?
Chapter learning outcomes
- @pytest.fixture
- parametrize
- conftest.py
- Fixture scope
Clear these before you leave
Side quest
URL builder tests
Parametrize build_url with trailing slash edge cases.