Reusable configuration and artifact utilities for building pytest plugins
Maintained. Last release 7 months ago, commits in 10 of the last 26 weeks. Weaker on contributor spread.
pip install pytest-plugin-utilsReusable pytest Plugin Utilities
Building pytest plugins means dealing with the same problems repeatedly: managing configuration options with proper precedence (CLI vs INI vs defaults), creating per-test artifact directories, and sanitizing test names for filesystem paths. This package extracts those common patterns into reusable utilities.
I created this after extracting the config and path handling logic from pytest-playwright-artifacts. Rather than reinvent option handling in every plugin, you can use these utilities to get consistent behavior across pytest plugins.
Installation
uv add pytest-plugin-utils
Usage
Configuration Options
Register pytest options with automatic precedence handling (runtime > CLI > INI > defaults) and type inference.
For Plugin Authors
from pytest_plugin_utils import set_pytest_option, register_pytest_options, get_pytest_option
def pytest_addoption(parser):
# Define your options (use __package__ for namespace)
set_pytest_option(
__package__,
"api_url",
default="http://localhost:3000",
help="API base URL",
available="all", # Expose via CLI and INI
type_hint=str,
)
# Register them with pytest
register_pytest_options(__package__, parser)
def pytest_configure(config):
# Retrieve with automatic type casting
api_url = get_pytest_option(__package__, config, "api_url", type_hint=str)
namespace is only used internally by this library to scope its option registry.
It does not prefix pytest's CLI flags, config.option attributes, or INI keys.
If you register "api_url", the runtime override is config.option.api_url, not a namespaced variant like config.option.my_plugin_api_url.
The available Parameter
The argument in controls how the option is exposed to the user: