Setups, Teardowns, Tags, Timeouts, and Suite Lifecycle: Core Concepts and Mental Model
Build a precise lifecycle model from suite setup through test/task setup, body, teardown, suite teardown, tags, timeouts, and final result evidence—without confusing metadata with isolation or cleanup with success.
Learning objectives
- Trace exact suite/test/task/keyword setup and teardown ordering and explain what executes after failures.
- Distinguish lifecycle ownership from tags, selection, variable scope, and external-system state.
- Explain how setup and teardown failures alter test/suite status and evidence.
- Separate test timeouts from user-keyword timeouts and understand why timeout is a last-resort safety fuse.
- Use tags as classification/selection metadata without treating them as environment configuration or isolation.
Current compatibility baseline. Verified
2026-08-31: Robot Framework 7.4.2 is the current stable release and
requires Python 3.8+; 7.5b1 is a pre-release and is not required
here. Suite, test/task, and user-keyword setups/teardowns are
supported; user-keyword [Setup] was added in Robot
Framework 7.0. Test Tags is the modern suite-level tag
setting, while Force Tags/Default Tags are
deprecated. Test timeouts and user-keyword timeouts have different
cleanup behavior, which this chapter treats explicitly.
1. The practical problem: cleanup must survive abnormal paths
Chapter 08 introduced owned side effects: temporary directories, files, child processes, transformed data, and evidence. Chapter 09 answers the next operational question: who creates those resources, who verifies them, and who cleans them when something fails or times out?
A reliable suite cannot depend on the happy path reaching its last keyword. Lifecycle hooks exist so preparation and cleanup have explicit ownership. Tags and timeouts influence what runs and how long it may run, but neither replaces cleanup design.
flowchart TD
A[Suite starts] --> B[Suite Setup]
B -->|PASS| C[Test/Task Setup]
B -->|FAIL| X[Contained tests marked FAIL]
C -->|PASS| D[Test/Task Body]
C -->|FAIL| E[Test/Task Teardown]
D --> E
E --> F{Next item?}
F -->|Yes| C
F -->|No| G[Suite Teardown]
X --> G
G --> H[Final statuses + output.xml/log/report]
T[Test timeout] -. interrupts current body keyword .-> E
K[Keyword timeout] -. can also apply in teardown .-> E
2. Four lifecycle levels, four ownership questions
| Level | Runs when | Typical ownership | Failure effect |
|---|---|---|---|
| Suite setup | Before tests and child suites | Shared prerequisite that truly belongs to entire suite | If it fails, contained tests are marked failed and child execution does not proceed |
| Test/task setup | Before one test/task body | Per-case isolated state | If it fails, body is skipped but teardown still executes |
| Test/task teardown | After the item regardless of status | Per-case cleanup/evidence | Failure contributes to final failure; all teardown keywords continue by default |
| Suite teardown | After all children/tests; even if matching suite setup failed | Shared suite cleanup | Failure marks tests in suite failed afterwards |
| User keyword setup/teardown | Around one user keyword | Reusable keyword-local preparation/cleanup | Setup failure skips body; teardown runs regardless of body status |
3. Test and task lifecycle settings are aliases, not different engines
When the file contains tasks rather than tests,
Task Setup, Task Teardown,
Task Tags, and Task Timeout are aliases
for the corresponding Test settings. The execution semantics are the
same; the terminology communicates automation intent. One file still
contains either tests or tasks, not both.
4. A setup or teardown is one keyword call
Robot Framework settings such as Suite Setup,
Test Setup, [Setup], and
[Teardown] name one keyword plus arguments. If several
actions belong together, create a higher-level user keyword whose
name explains the contract. This keeps the lifecycle setting
readable and the individual steps visible in log.html.
*** Settings ***
Test Setup Prepare Isolated Workspace
Test Teardown Collect Evidence And Cleanup
*** Keywords ***
Prepare Isolated Workspace
Create Directory ${WORKSPACE}
File Should Exist ${FIXTURE}
Collect Evidence And Cleanup
Capture Safe Evidence
Remove Owned Workspace
5. Failure does not mean “nothing else runs”
Normal test execution stops at the first non-continuable failure. Teardown is different: Robot Framework enables continue-on-failure through teardown levels so cleanup steps are attempted even if an earlier teardown step fails. That is useful, but it creates a design obligation: cleanup steps should be independently safe and should not assume the previous teardown step succeeded.
Primary-failure rule. A teardown can add its own failure to the test result. Do not put fragile business assertions into cleanup merely because teardown is guaranteed to run. Capture first-failure evidence early, then make cleanup narrow, idempotent where practical, and independently guarded.
6. Timeout is a safety fuse, not synchronization
Robot Framework supports test/task timeouts and user-keyword timeouts. A test timeout stops the currently executing keyword when the remaining test budget expires, fails the test, and then allows test teardown to run without the test timeout interrupting it. A user-keyword timeout applies to that keyword—including when the keyword is used in teardown—so it can bound a cleanup helper that might otherwise hang.
Timeouts forcibly interrupt execution and may leave a library or external system in an unstable state. Prefer domain-specific bounded waits and library-level timeouts. Use Robot Framework timeout only when there is no safer control.
8. Reserved robot:* tags are execution controls (lifecycle-relevant subset)
| Reserved tag | Effect | Design warning |
|---|---|---|
| robot:skip | Include in results as SKIP without executing body | Use for explicit skip semantics, not as generic metadata |
| robot:exclude | Omit from execution entirely | Excluded tests do not appear as skipped evidence |
| robot:skip-on-failure | Convert a failure into SKIP | Can hide readiness problems if used as a permanent flake policy |
| robot:exit-on-failure | Stop the whole execution when a tagged test fails | High blast radius; use only with explicit governance |
| robot:continue-on-failure | Make failures continuable in tagged scope | Does not make the test pass; failures remain failures |
| robot:recursive-continue-on-failure | Propagate continuable behavior into called user keywords | Use sparingly; broad continuation can create noisy cascading failures |
| robot:stop-on-failure / recursive variant | Disable continuation where it would otherwise apply | Can be useful in teardown/template scopes but should not replace clear ownership |
9. Final status is a lifecycle result, not only a body result
A test passes only when the executed test path has no failures. A setup failure can fail a test before its body runs; a teardown failure can fail a test after a successful body. Suite teardown can retroactively fail tests in that suite. The report therefore represents the complete lifecycle contract, not just assertions inside the body.
10. Why this matters in DevOps
CI reruns, parallel workers, and failure triage all assume each test
owns a deterministic lifecycle. When setup allocates unique state,
teardown preserves first-failure evidence and cleans only owned
resources, and tags describe intent instead of hiding configuration,
the resulting output.xml becomes trustworthy
operational evidence.
11. Knowledge check
If a test setup fails, does the test teardown still run?
Yes. The test body is skipped, but the test teardown is executed.
Can a test timeout interrupt its own test teardown?
No. Test teardown is not interrupted by the test timeout, although the test remains failed. A user-keyword timeout inside teardown can still bound a teardown keyword.
What happens when a suite teardown fails?
Tests in that suite are marked failed afterwards in logs/reports, so suite teardown failure changes final status.
Can a tag added with Set Tags cause the current test to be selected by --include after execution already started?
No. Runtime tags can affect result metadata/statistics, but selection of the current test has already happened.
Why should tags not hold environment URLs or credentials?
Tags are classification/selection metadata and are widely visible in source/results. Configuration and secrets have different ownership and safety requirements.
12. Summary and next step
You now have the lifecycle mental model: setup prepares owned state, the body exercises intent, teardown preserves evidence and cleans up, suite teardown handles genuinely shared suite resources, tags classify/select, and timeout is a bounded emergency stop. Lesson 2 turns this model into an instrumented local suite whose marker file proves the exact order under PASS, FAIL, and TIMEOUT paths.
Further reading
- Robot Framework 7.4.2 User Guide — test setup and teardown — defaults, overrides, teardown guarantees, and task aliases.
- Robot Framework 7.4.2 User Guide — execution flow — suite/test/keyword setup and teardown ordering and failure semantics.
- Robot Framework 7.4.2 User Guide — timeouts — test versus user-keyword timeout behavior and safety cautions.
- Robot Framework 7.4.2 User Guide — tags — Test Tags, reserved tags, include/exclude/skip semantics, and deprecations.
- Robot Framework 7.4.2 BuiltIn — Set Tags, Remove Tags, Skip/Skip If, and status/control helpers.
- Robot Framework on PyPI — current stable/pre-release stream and Python requirement.
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0
Send only Ethereum/ERC-20 compatible assets to this
address.