Chapter 09Lesson 01140–190 min

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.

LifecycleFixturesTagsTimeoutsResult semantics

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.

Lifecycle order and result flow
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.

7. Tags classify and select; they do not isolate state

Normal tags are free-text metadata used in source, logs, reports, statistics, and command-line selection. Test Tags adds common tags to a suite; [Tags] adds or removes tags on an individual test; BuiltIn Set Tags/Remove Tags can modify the current test’s tags at runtime.

Selection happens before the test body executes. A tag added dynamically can appear in results, but it cannot retroactively cause the current test to have been selected. Environment URLs, credentials, ports, and account identities belong in configuration variables—not tags.

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?

Can a test timeout interrupt its own test teardown?

What happens when a suite teardown fails?

Can a tag added with Set Tags cause the current test to be selected by --include after execution already started?

Why should tags not hold environment URLs or credentials?

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.

Next lesson

Setups, Teardowns, Tags, Timeouts, and Suite Lifecycle: Guided Hands-On Workflow

Continue with Setups, Teardowns, Tags, Timeouts, and Suite Lifecycle: Guided Hands-On Workflow. It builds directly on the state, evidence, and operating assumptions established here, so carry those constraints forward rather than treating the next page as an isolated topic.

Further reading

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.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.