Skip to content

Initialization files

Lesson lab: Initialization filesch06-structure-control--initialization-files.zip · 4 KB

This lesson starts from a fresh lab — download it even if you already have the chapter lab.

Download ch06-structure-control--initialization-files.zip

Or fetch and unpack it from a terminal in VS Code:

Terminal window
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch06-structure-control--initialization-files.zip && unzip -q ch06-structure-control--initialization-files.zip && rm ch06-structure-control--initialization-files.zip

Open the folder in VS Code with code rfe-ch06-structure-control--initialization-files (or File → Open Folder…) and accept the recommended RobotCode and Python extensions. Then set it up:

Terminal window
uv sync
Terminal window
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Keep the environment active in every terminal where you run lesson commands.

Terminal window
poetry install --no-root

Python 3.13 or newer is required; uv installs it when it is missing.

Open in browserNo setup? Try the lab right here: its files, an editor and a terminal, running in your browser.

What's inside
  • Directoryrfe-ch06-structure-control--initialization-files/
    • Directory.vscode/
      • extensions.json
    • Directorychecks/
      • Directorycatalog/
        • catalog.robot
      • Directorysmoke/
        • smoke.robot
    • .gitignore
    • .python-version
    • LAB.md
    • pyproject.toml
    • README.md
    • requirements.txt
    • uv.lock

A folder of suite files is a directory suite. To give the whole folder shared settings — documentation, a suite setup, a teardown — you add an __init__.robot file to it. It holds settings, not test cases.

This chapter’s workspace has checks/ with two sub-suites, smoke/ and catalog/. Download this lesson’s lab, then add an initialization file so the whole directory shares one suite setup.

Task 1 — Add a init.robot with a suite setup

Section titled “Task 1 — Add a init.robot with a suite setup”
Edit

Goal: create checks/__init__.robot with documentation and a suite setup for the whole directory. It has no test cases — it configures the folder.

Here is the same *** Settings *** block in a normal suite (with a test so it runs). Your init file uses the same settings, but drops the test.

Worked example — adapt it, don’t copy it

*** Settings ***
Documentation A folder with a shared setup.
Suite Setup Log Preparing the folder
*** Test Cases ***
Placeholder
Log ok

Done when

checks/__init__.robot exists and defines a Suite Setup.

Hint 1

Create the file at exactly checks/__init__.robot — two underscores on each side of init.

Hint 2

In *** Settings ***, add Documentation Checks directory suite. and Suite Setup Log Starting the checks directory. Add no test cases.

Solution
*** Settings ***
Documentation Checks directory suite.
Suite Setup Log Starting the checks directory
Run

Run the whole directory:

Terminal window
uv run robot checks
Terminal window
robot checks
Terminal window
poetry run robot checks

Robot Framework runs the initialization file’s setup once, then the sub-suites.

Done when

the run finished cleanly (exit code 0).

Check your understanding

Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.

  1. What is __init__.robot for?

    Show the answer

    Answer: It defines settings (setup/teardown, docs) for a directory suite — A directory suite's __init__.robot holds suite-level settings — documentation, setup/teardown — for the whole folder.

  2. Can __init__.robot contain test cases?

    Show the answer

    Answer: No — it holds settings, not tests — Initialization files configure the directory suite; test cases live in the regular suite files.

Key terms

__init__.robotconcept
Directory-suite initialization file: settings and setup/teardown for a whole folder of suites.

All terms in the glossary →