Chapter 09Lesson 03140–190 min

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.

Design trade-offsFixture scopeTimeout policyTag strategyGovernance

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:

  1. preserve first-failure evidence;
  2. attempt cleanup using resource identifiers owned by the current test;
  3. verify the important postcondition (for example, the owned directory no longer exists);
  4. 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.

7. Static tags, runtime tags, and configuration

Static tags are best for durable classification such as smoke, contract, owner-payments, or requires-local-fixture. Runtime tags can record an observation discovered during execution, such as feature-flag-on, but they should not be used to decide the current test’s environment after selection.

Environment values belong in variables or future execution profiles/argument files. Tags may describe an environment requirement; they should not be the environment itself.

8. Prefer Test Tags over legacy Force Tags/Default Tags

Test Tags is the modern suite-level setting. If one test should remove a common tag, [Tags] -tag supports removal. Legacy Force Tags and Default Tags still work in 7.4.2 but are deprecated and should not be the basis of new course content.

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?

When is suite setup appropriate?

Which timeout should usually be preferred for an HTTP request that can hang?

Why is Test Tags preferable to Force Tags in new content?

What is wrong with storing an environment URL in a tag?

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.

Next lesson

Setups, Teardowns, Tags, Timeouts, and Suite Lifecycle: Diagnostics, Failure Modes, and Production Practices

Continue with Setups, Teardowns, Tags, Timeouts, and Suite Lifecycle: Diagnostics, Failure Modes, and Production Practices. 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.