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.
In more detail
In a pytest yield fixture, everything before yield is setup and everything after it is teardown, which runs even when the test fails. Older frameworks use separate setUp and tearDown methods that run for every test whether it needs them or not.
Related terms
- fixture — A named piece of setup, defined with @pytest.fixture, that a test receives by listing the fixture's name as a parameter.
- 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.
- context manager — An object that sets something up and later tears it down, designed to be used with a with statement.
- test isolation — The property that each test sets up everything it needs and leaves nothing behind, so tests pass in any order.
Taught in
- 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