TEST @teardown
Test files only
This annotation applies only to test files run by the SQL test runner (npgsqlrest --test). It has no meaning in endpoint SQL files or routine comments.
Run one or more named steps (from the TestRunner.Steps registry) after this test file — always, best-effort, even when the file failed or errored.
Syntax
Placed in the file's header — the leading -- line comments before the first SQL statement or HTTP block:
sql
sql
-- @teardown StepName [StepName ...]- Names may be whitespace- or comma-separated; the annotation is repeatable; steps run in the order written.
- Every name must exist in the
TestRunner.Stepsregistry. - Runs after the file's own connection is disposed, so it can safely
drop database ... with (force)on an admin connection.
Example
sql
sql
-- @setup CreateIsolatedDb
-- @teardown DropIsolatedDb
-- @connection Isolated
begin;
insert into users (name) values ('fixture');
select count(*) = 1, 'fixture inserted in the private clone' from users;
rollback;Even if the assertion fails — or the file errors halfway — DropIsolatedDb still runs, so the per-file database never leaks.
Ordering
For one test file the lifecycle is:
- per-file
@setupsteps (in written order) - the file body, on its own non-pooled connection
- connection disposed
- per-file
@teardownsteps (in written order, always)
The run-level TestRunner.Setup/Teardown wrap the whole run outside of this.
Related
- TEST @setup — the mirror, runs before the file
- TEST @connection — run the file on another connection
- Test Runner configuration
- Testing Guide