pytest-env
pytest plugin that allows you to add environment variables.
Decision gist · record as of 2026-08-14
Yes. This is a mature, actively maintained plugin (first released in 2015, latest in 2026) with no known vulnerabilities, low install friction, and a clear, focused purpose. It solves a real problem—managing test environment variables—in a standard, declarative way. The MIT license imposes no restrictions. Install it if you need to manage environment variables across test suites.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low install friction with a pure-Python wheel.
- Actively maintained with a recent release; last commit was 24 days ago.
License · maintenance · safety
permissive license (permissive) — MIT License permits unrestricted use, modification, and distribution with only attribution required. No restrictions on commercial or private use.
last release 2026-07-21 (24 days) · last repo commit 2026-08-10 · 233 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 24,043,458 downloads/mo, #928 on PyPI
Alternatives
Verify before relying
pip install pytest-env
# Add to pyproject.toml:
# [tool.pytest_env]
# DATABASE_URL = "postgresql://localhost/test_db"
# DEBUG = "true"
# In test file:
import os
def test_example():
assert os.environ["DATABASE_URL"] == "postgresql://localhost/test_db"What it is and what it does
pytest-env is a pytest plugin that automatically injects environment variables into your test session from configuration files or .env files. It reads from pyproject.toml (under [tool.pytest_env]), pytest.toml, .pytest.toml, pytest.ini, or any .env file you specify, and makes those variables available to your tests via os.environ. The plugin supports variable expansion using existing environment variables, conditional assignment (skip if already set), and unsetting variables entirely.
The main use case is eliminating the need to manually set environment variables before running tests or hardcoding them in test files. You define test-specific configuration once in your project's config file, and the plugin ensures it's applied consistently across all test runs. It also supports per-directory configuration overrides, so integration tests can use different settings than unit tests by placing a pytest.toml in a subdirectory.
Use it for
- Set database connection strings or API endpoints for test suites without modifying shell environment or test code.
- Load secrets and credentials from .env files during test execution while keeping them out of version control.
- Override parent-level environment settings for specific test directories (e.g., integration tests vs. unit tests).
- Expand environment variables in config values using {VAR} placeholders to reference existing system or pytest-set variables.
- Debug environment variable assignments with --pytest-env-verbose to see exactly what was set and from which config file.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
This is a mature, actively maintained plugin (first released in 2015, latest in 2026) with no known vulnerabilities, low install friction, and a clear, focused purpose. It solves a real problem—managing test environment variables—in a standard, declarative way. The MIT license imposes no restrictions. Install it if you need to manage environment variables across test suites.
Install
pytest-env on PyPI
Before you install
Low install friction with a pure-Python wheel. Actively maintained with a recent release; last commit was 24 days ago. Depends only on pytest, python-dotenv, and tomli—all stable, widely-used packages.
Requires Python 3.10 or later.
License in practice
MIT License permits unrestricted use, modification, and distribution with only attribution required. No restrictions on commercial or private use.
Quickstart
pip install pytest-env
# Add to pyproject.toml:
# [tool.pytest_env]
# DATABASE_URL = "postgresql://localhost/test_db"
# DEBUG = "true"
# In test file:
import os
def test_example():
assert os.environ["DATABASE_URL"] == "postgresql://localhost/test_db"
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagespytestpython-dotenvtomli |
| Maintenance | Actively maintained 24 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 24,043,458 / month, #928 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development :: Libraries :: Python Modules |
Evidence: pytest_env-1.7.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pytest environment variables”
- pytest-envA pytest plugin that loads environment variables from configuration…
- pytest-dotenvA pytest plugin that automatically loads environment variables from…
- pytest-metadataA pytest plugin that captures and exposes test session…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also pytest-dotenv · tempenv · python-decouple · poetry-dotenv-plugin · envsubst · dotenv · python-dotenv · pytest-pythonpath · maison · pytest-variables