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.2.tar.gz (7.3 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.2.tar.gz.

File metadata

File hashes

Hashes for robotframework_env_manage_library-0.1.2.tar.gz
Algorithm Hash digest
SHA256 54cf65c717c575b0584c853cd2cd73b28cfaeeb36041fbe37d15b305472789db
MD5 59da2553557259a27812f7212b1632f0
BLAKE2b-256 51795bce91c56b29ee5ef9a77cb5260c5ff4009b862c44b56f7e7e564d976f88

See more details on using hashes here.

Provenance

The following attestation bundles were made for robotframework_env_manage_library-0.1.2.tar.gz:

Publisher: publish.yml on Non-Spk/robotframework-env-manage-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for robotframework_env_manage_library-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 02a80b1b1245b20538820bb19750c21357bfb794a25ccde833309e768cc300cb
MD5 3d773eb0617c2d3a14d700acc90075f2
BLAKE2b-256 027d5d43d7ddd237a5c497f9954b21b181b114e29bdc447d316ab7792978ebd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for robotframework_env_manage_library-0.1.2-py3-none-any.whl:

Publisher: publish.yml on Non-Spk/robotframework-env-manage-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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