Setups, Teardowns, Tags, Timeouts, and Suite Lifecycle: Configuration, Design Patterns, and Trade-Offs
Choose fixture scope, tag strategy, timeout boundaries, and teardown strictness deliberately so convenience does not create hidden coupling, false greens, or unreliable CI cleanup.
Learning objectives
- Decide when state belongs in suite setup versus isolated test/task setup.
- Compare test timeout and user-keyword timeout as different safety boundaries.
- Use static and runtime tags for classification while keeping environment configuration in variables/profiles.
- Design teardown to preserve primary evidence without silently tolerating dirty external state.
- Evaluate lifecycle choices for maintainability, parallel safety, portability, and CI reliability.
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. Suite-scoped fixture versus per-test isolation
| Choice | Good fit | Benefit | Risk |
|---|---|---|---|
| Suite setup | Expensive immutable prerequisite shared safely by all tests | Avoid repeated setup cost | One failure blocks many tests; shared mutable state can create order dependence |
| Test/task setup | Accounts/files/records/browser state that a case mutates | Strong isolation and easier parallelism | More setup cost |
| User keyword setup | Reusable keyword-local precondition | Keeps local contract close to abstraction | Can hide work if overused |
| No fixture; explicit body keyword | Preparation is part of test intent itself | Very visible intent | Cleanup still needs reliable ownership |
2. The scope rule: choose the narrowest owner that is still correct
Do not promote state to suite scope merely because setup is expensive. Shared mutable resources couple tests and make parallel execution unsafe. A suite-level fixture is strongest when it is immutable after setup or when the entire suite intentionally models one shared workflow. Per-test state should remain the default when tests can independently create it.
3. Default fixtures versus explicit overrides
Test Setup/Test Teardown in Settings
define defaults. A test can override them with
[Setup]/[Teardown], and an empty setting
disables the default. That power should be visible in code review
because one test that silently disables cleanup can contaminate
later cases.
*** Settings ***
Test Setup Prepare Case
Test Teardown Cleanup Case
*** Test Cases ***
Uses Defaults
Verify Something
Different Setup
[Setup] Prepare Special Case
Verify Something
No Teardown Teaching Example
[Teardown]
Log Disables the default teardown -- use only deliberately
4. Teardown strictness versus primary failure
Two bad extremes are common. A teardown that ignores every error can leave dirty state while reporting a clean cleanup path. A teardown that performs many brittle assertions can generate secondary failures that distract from the original defect.
A safer production pattern is:
- preserve first-failure evidence;
- attempt cleanup using resource identifiers owned by the current test;
- verify the important postcondition (for example, the owned directory no longer exists);
- report cleanup failure clearly without deleting or rewriting the original evidence.
5. Test timeout versus user-keyword timeout
| Boundary | Covers | Teardown interaction | Typical use |
|---|---|---|---|
| Test/Task Timeout | Overall test/task execution budget | Does not interrupt test teardown after timeout | Last-resort cap for a case that could otherwise run indefinitely |
| User keyword [Timeout] | One reusable keyword, including nested calls | Still applies when keyword runs inside teardown | Bound a cleanup or external operation that itself might hang |
| Library/domain timeout | Specific browser/API/process/DB/SSH operation | Library-specific | Preferred because it can stop the actual operation safely and report context |
6. Timeouts are budgets, not readiness checks
If the business requirement is “wait until service becomes healthy,” encode an observable condition with a bounded polling mechanism in the appropriate library layer. A giant test timeout only says how long Robot will tolerate the entire case. It does not explain what condition is awaited and may interrupt execution at an arbitrary point.
9. Worked decision table
| Scenario | Recommended design | Reason |
|---|---|---|
| Each test edits its own JSON file | Per-test setup/teardown with unique file path | Isolation outweighs tiny setup cost |
| Suite requires one read-only local fixture directory | Suite setup verifies/creates immutable fixture; suite teardown removes only if suite owns it | Safe shared prerequisite |
| External call can hang independently | Library/domain timeout first; keyword timeout as outer safety net | Stops closest to the actual operation |
| Need to run only smoke tests |
Static smoke tag + --include smoke
|
Clear selection metadata |
| Need to pass API base URL | CLI/variable file/environment variable according to secret policy | Configuration is not tag metadata |
| Cleanup sometimes fails | Preserve first failure, bounded cleanup, verify owned postcondition | Avoid both silent dirt and teardown noise |
10. Parallel-safety preview
Pabot arrives later in the course, but lifecycle design must prepare for it now. Shared filenames, shared accounts, fixed ports, and mutable suite-level objects are future parallel collisions. Use run/test identifiers and narrow ownership even when today’s execution is serial.
11. Knowledge check
What is the default fixture choice for mutable per-test state?
Per-test/task setup and teardown, because the narrow owner provides isolation and easier parallelism.
When is suite setup appropriate?
For a genuinely suite-wide prerequisite, ideally immutable or intentionally shared, whose failure should block the suite.
Which timeout should usually be preferred for an HTTP request that can hang?
A timeout in the HTTP/library layer because it controls the actual operation. Robot test/keyword timeout can remain an outer safety net.
Why is Test Tags preferable to Force Tags in new content?
Test Tags is the modern setting; Force Tags and Default Tags are deprecated legacy settings.
What is wrong with storing an environment URL in a tag?
It mixes selection metadata with runtime configuration and exposes changing operational state in reports/source.
12. Summary and next step
Good lifecycle configuration is mostly about ownership: narrow mutable fixtures, explicit defaults and overrides, condition-specific waits, bounded timeouts, durable classification tags, and cleanup that preserves evidence. Lesson 4 applies that design model to realistic failures—shared-state leakage, teardown noise, overbroad timeouts, order dependence, and unsafe cleanup.
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.