fixture
A named piece of setup, defined with @pytest.fixture, that a test receives by listing the fixture's name as a parameter.
In more detail
pytest sees the parameter, builds the fixture, passes in its value and can tear it down afterwards. Setup that no test asks for never runs. Fixtures can use other fixtures, and their scope decides how often they are rebuilt.
Examples
bash make-fixture-repo.sh fixture # a pinned history, so your metrics match the lessonbash make-fixture-repo.sh fixture@pytest.fixture
def basket():
return [(250, 2), (125, 4)]Related terms
- deterministic — Always producing the same result from the same inputs, with nothing left to chance or timing.
- test suite — A collection of tests run together to check a piece of software.
- fixture scope — How long pytest keeps one fixture value before building a new one: per test function, class, module, package or whole session.
- setup and teardown — The work done before a test to prepare what it needs, and after it to clean up, such as closing files or stopping containers.
- conftest.py — A special pytest file whose fixtures and hooks are available to every test in its directory and below without importing them.
- yield — The keyword that makes a function a generator: yield value hands one value to the caller and pauses until the next one is asked for.
Taught in
- Throughput: Change Lead Time And Deployment Frequency — DevOps & Site Reliability Engineering
- The Pitfalls Of Measurement — DevOps & Site Reliability Engineering
- Trunk-Based Development Versus Git Flow — DevOps & Site Reliability Engineering
- Deployment Strategies: Rolling Updates — DevOps & Site Reliability Engineering
- Deployment Strategies: Canary Releases — DevOps & Site Reliability Engineering
- Decoupling Release From Deployment: Feature Flags — DevOps & Site Reliability Engineering
- Fixtures And Their Scope — Automated Testing, TDD & Quality Engineering
- Testing The Filesystem — Automated Testing, TDD & Quality Engineering
- Integration Testing With Containers — Automated Testing, TDD & Quality Engineering
- Testing With Real Databases — Automated Testing, TDD & Quality Engineering