Skip to main content

Robot Framework library to override test variables from .env files

Project description

EnvManageLibrary

Robot Framework keyword library that overrides test variables with values from .env files.

Documentation

Variables loaded via Robot Framework's Variables directive (from YAML files) are automatically matched against .env entries and overridden at test-case scope.

Installation

Option 1: From PyPI

pip install robotframework-env-manage-library

Option 2: From local .whl / .tar.gz file

pip install robotframework_env_manage_library-0.1.0-py3-none-any.whl

Option 3: From local packages directory (offline)

pip install --no-index --find-links=./packages robotframework-env-manage-library

.env Naming Convention

The dot (.) separator distinguishes nested dict keys from flat variable names containing underscores.

.env Key RF Variable Type
USER=value ${user} Flat
DB_HOST=value ${db_host} Flat
AUTHEN.USER=value ${authen}[user] Nested dict
DB.CONN.HOST=value ${db}[conn][host] Deep nested dict

Usage

YAML data files

# data/credentials.yaml
user: testuser
pass: "default_pass"
# data/config.yaml
db:
  host: localhost
  port: "5432"

.env file

# Flat overrides
USER=admin
PASS=S3cretK3y!

# Nested dict overrides (use dot separator)
DB.HOST=prod-db.example.com
DB.PORT=5433

Robot Framework test

*** Settings ***
Library    EnvManageLibrary
Variables  ${CURDIR}/data/credentials.yaml
Variables  ${CURDIR}/data/config.yaml

*** Test Cases ***
Verify Credentials Override
    Override Variables From Env    path/to/.env
    Should Be Equal    ${user}    admin
    Should Be Equal    ${pass}    S3cretK3y!

Verify Config Override
    Override Variables From Env    path/to/.env
    Should Be Equal    ${db}[host]    prod-db.example.com
    Should Be Equal    ${db}[port]    5433

Values Reset Between Tests
    # No override called - original YAML values are intact
    Should Be Equal    ${user}    testuser
    Should Be Equal    ${db}[host]    localhost

How It Works

  1. Robot Framework loads YAML files via Variables, creating RF variables
  2. Override Variables From Env parses the .env file
  3. For each RF variable, it checks for a matching .env key:
    • Flat string variables: YAML key user matches env key USER
    • Dict variables: YAML key db with child host matches env key DB.HOST
  4. Matched values are overridden using Set Test Variable (scoped to current test only)
  5. Original YAML values remain intact for other test cases

Key Behaviors

  • Override scope is per test case - original values reset between tests
  • If .env file doesn't exist, all variables keep their YAML values
  • Case insensitive - YAML user matches env USER
  • Flat keys with underscores (DB_HOST) only override flat RF variables (${db_host}), not nested dicts
  • Dict values are deep-copied before override to prevent mutation

Development

git clone https://github.com/Non-Spk/robotframework-env-manage-library.git
cd robotframework-env-manage-library
python -m venv venv

# Windows
venv\Scripts\pip install -e ".[dev]"
venv\Scripts\pytest -v

# macOS / Linux
source venv/bin/activate
pip install -e ".[dev]"
pytest -v

Building

pip install build
python -m build

This produces dist/robotframework_env_manage-0.1.0-py3-none-any.whl and dist/robotframework_env_manage-0.1.0.tar.gz.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework_env_manage_library-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file robotframework_env_manage_library-0.1.1.tar.gz.

File metadata

File hashes

Hashes for robotframework_env_manage_library-0.1.1.tar.gz
Algorithm Hash digest
SHA256 44cd3d46e0d9fcfb75d20ac203d0ac9be5eb426ea7660d550c57995a1bcf5650
MD5 c65136c45d2423d03e4b71e74e506893
BLAKE2b-256 8b27e3563eee88ca8bfe644a5fc6b032705d12a25fe9fa29454eb3036e078423

See more details on using hashes here.

File details

Details for the file robotframework_env_manage_library-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_env_manage_library-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ba9f6b3cd8104ea6850a979d56aa19e31e8fcad68b8a3b69ca0ef1a6d85486b
MD5 2e86dfc0599f6c5de2b88da1657078b9
BLAKE2b-256 ea4057e0ae27d53daa7ea91e34bc4f766b360bbf7ec00a1e81a8277941ccb649

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page