Setups, Teardowns, Tags, Timeouts, and Suite Lifecycle: Diagnostics, Failure Modes, and Production Practices
Diagnose lifecycle failures by preserving first-failure evidence, separating fixture/body/teardown causes, and repairing the smallest ownership boundary instead of adding retries, giant timeouts, or destructive cleanup.
Learning objectives
- Classify failures as setup, body, teardown, timeout, tag-selection, or external-state problems.
- Diagnose teardown failures without losing the original body failure.
- Recognize shared fixture leakage and order dependence from evidence rather than rerun folklore.
- Reject giant timeouts, broad retries, and unsafe process/filesystem cleanup as troubleshooting shortcuts.
- Apply a repeatable least-destructive diagnostic sequence and produce a repair evidence packet.
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. Diagnostic sequence
-
Preserve first-failure artifacts: copy/retain
output.xml,log.html, report, marker files, and owned external evidence. - Confirm versions and exact command: Robot/Python, executed path, include/exclude/skip filters, variables, output directory.
- Classify lifecycle phase: suite setup, test setup, body, test teardown, suite teardown, or timeout.
- Inspect variable and keyword resolution: setup/teardown overrides, imported resource, active timeout, runtime tags.
- Inspect owned external state: files/processes/records created by this test only.
- Apply the smallest correction and rerun the smallest controlled slice into a new evidence directory.
3. Failure mode: teardown noise obscures the primary failure
A test fails because the system behavior is wrong. Teardown then executes a fragile “should exist” assertion on a file that was never created because setup partially failed. The final result now contains multiple failures. Robot Framework preserves failures, but humans may focus on the last cleanup message instead of the initiating defect.
*** Test Cases ***
Broken Example
[Teardown] Brittle Cleanup
Fail primary-business-failure
*** Keywords ***
Brittle Cleanup
File Should Exist ${OPTIONAL_FILE}
Remove File ${OPTIONAL_FILE}
Repair: make cleanup conditional on resource ownership/existence, record whether cleanup was needed, and keep a meaningful postcondition. Do not suppress all cleanup errors; distinguish “nothing to clean” from “owned resource could not be removed.”
4. Failure mode: giant timeouts become operational fog
A 30-minute test timeout does not explain whether the browser, API, process, or database operation is stuck. It delays feedback and makes incident timing ambiguous. First configure a specific timeout in the operation that can block. Keep a smaller Robot-level timeout only as a final guard.
6. Failure mode: order-dependent tests
Robot Framework executes tests in source order by default and nested suites according to documented suite-order rules. Stable order is not permission to share dirty state. A production suite should remain correct if a single test is selected or if future parallel execution changes scheduling.
7. Failure mode: teardown kills or deletes by broad pattern
Never clean by guess. Commands such as “kill every python process,” recursive deletion of a parent temp directory, or deleting every record with a common prefix can affect unrelated tests, developer tools, or production-like resources. Store exact resource identifiers when you create them and clean only those identifiers.
For filesystem state, normalize and guard the exact path. For processes, retain a handle/alias or PID owned by the test. For database/API records, retain generated IDs. For browser sessions, teardown the exact driver/session object owned by the test.
8. Failure mode: “teardown passed” is mistaken for external cleanliness
A cleanup keyword returning PASS only proves the keyword reported success. Production-grade cleanup may require an independent postcondition: directory absent, process stopped, row deleted, session closed, or synthetic account disabled. Verify the important state—without querying unrelated resources.
9. Controlled broken lifecycle case
*** Settings ***
Library OperatingSystem
Test Setup Create Per Test File
Test Teardown Broken Cleanup
*** Variables ***
${ROOT} ${TEMPDIR}/rf09-diagnostic
*** Test Cases ***
Primary Failure Must Stay Visible
Fail primary-failure-RF09
*** Keywords ***
Create Per Test File
Create Directory ${ROOT}
${path}= Join Path ${ROOT} owned.txt
Set Test Variable ${OWNED} ${path}
Create File ${OWNED} evidence
Broken Cleanup
Remove File ${OWNED}
File Should Exist ${OWNED}
Expected result: the body fails, cleanup removes the file, then the
bad teardown assertion also fails. Preserve this result. Repair the
final assertion to File Should Not Exist, add a guarded
directory cleanup, and rerun into a new output directory. The
repaired run should still FAIL because the intentionally injected
primary failure remains.
10. Evidence packet for diagnosis
| Question | Evidence to preserve |
|---|---|
| Which phase failed first? | log.html keyword hierarchy + timestamped marker file |
| Was the body executed? | body marker / keyword nodes in output.xml |
| Did teardown execute after failure? | teardown keyword nodes and cleanup postcondition |
| Which filters were active? | exact robot command and included/excluded/skipped tags |
| Was timeout responsible? | failure message + active [Timeout]/Test Timeout/keyword timeout |
| Did cleanup affect only owned state? | exact resource path/ID and post-cleanup verification |
11. Troubleshooting shortcuts to reject
- Blanket reruns until green.
- Increasing every timeout without measuring the blocked operation.
-
Adding
robot:skip-on-failureto flaky production tests. - Ignoring teardown failures globally.
- Turning mutable per-test state into suite/global variables.
- Deleting the failing output directory before diagnosis.
- Disabling TLS/SSH verification or experimenting on production targets to “reproduce faster.”
12. Knowledge check
A test passes alone but fails after another test. What should you suspect first?
Shared mutable state or order dependence, especially suite-scoped fixtures/files/accounts modified by the earlier test.
If teardown adds a second failure, should you ignore all teardown errors?
No. Preserve the primary failure, make cleanup tolerant only where absence is acceptable, and still verify important cleanup postconditions.
Why is killing every matching process unsafe?
The pattern can match processes the current test does not own. Cleanup should target the exact handle/PID/alias created by the test.
What should happen after repairing teardown in an intentionally failing diagnostic test?
The primary injected failure should remain FAIL, while the secondary cleanup failure disappears and cleanup postconditions pass.
13. Summary and next step
Lifecycle diagnosis is phase-oriented and evidence-first. Preserve the original run, identify whether setup/body/teardown/timeout/selection failed, verify only owned external state, and repair the smallest boundary. Lesson 5 combines the chapter into a lifecycle matrix checkpoint with PASS, FAIL, TIMEOUT, teardown evidence, tag selection, and a shared-state refactor.
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.