Registry / testing / pytest-fixture-config

pytest-fixture-config

JSON →
library1.8.0pypypi✓ verified 87d ago

pytest-fixture-config is a pytest plugin that provides utility functions for configuring Py.test fixtures. It enables the creation of simple configuration objects for fixtures, allowing tests to be skipped dynamically if required configuration variables are not set. The library is part of the larger `man-group/pytest-plugins` monorepo, is currently in version 1.8.0, and maintains an active release cadence with frequent updates.

pip install pytest-fixture-config
INSTALL
IMPORT
SIG · PYTEST-FIXTURE-CON
P
pytest-fixture-config
testingpythonv1.8.0
Install
2.7s avg
Import
439ms
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.470s · 30.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.7s · import 0.408s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Config
from pytest_fixture_config import Config
requires_config
from pytest_fixture_config import requires_config
yield_requires_config
from pytest_fixture_config import yield_requires_config

This quickstart demonstrates how to define a configuration class using `pytest_fixture_config.Config`, populate it from environment variables, and use the `requires_config` decorator to create fixtures that conditionally skip tests if necessary configuration values are not provided. This ensures tests requiring specific setups only run when their prerequisites are met.

import os import pytest import subprocess from pytest_fixture_config import Config, requires_config # 1. Define your configuration class inheriting from Config class MyAppConfig(Config): __slots__ = ('api_key', 'base_url') # Define expected config attributes # 2. Create a singleton instance, reading from environment variables APP_CONFIG = MyAppConfig( api_key=os.environ.get('MY_APP_API_KEY'), # No default, required base_url=os.environ.get('MY_APP_BASE_URL', 'https://api.example.com') # With default ) # 3. Use requires_config decorator to make fixtures dependent on config @pytest.fixture @requires_config(APP_CONFIG, ['api_key']) def authenticated_client(): """Provides an authenticated client if API_KEY is set.""" print(f"\nUsing API Key: {APP_CONFIG.api_key[:5]}... and Base URL: {APP_CONFIG.base_url}") # In a real app, this would initialize an API client class MockClient: def fetch_data(self): return {"status": "data_fetched"} return MockClient() def test_data_fetch(authenticated_client): """This test requires a valid API_KEY to run.""" assert authenticated_client.fetch_data() == {"status": "data_fetched"} # To run this example: # 1. Save as `test_app.py` # 2. Run: `pytest -s test_app.py` (it will be skipped) # 3. Set env var: `export MY_APP_API_KEY="your_secret_key"` # 4. Run again: `pytest -s test_app.py` (it should pass)
Debug
Known issues
breakingPython 2 and Python <3.6 support has been dropped. All compatibility code for older Python versions was removed in v1.8.0.
fix
Upgrade your Python environment to version 3.6 or newer.
affects: >=1.8.0
breakingThe `mock` package is no longer used. All mock-related functionality now uses the standard library's `unittest.mock` module.
fix
Update any code directly importing or relying on the standalone `mock` package to use `unittest.mock` instead.
affects: >=1.8.0
breakingUsage of `path.py` and `path` has been removed in favor of `pathlib` for file system path operations.
fix
Refactor any code interacting with `pytest-fixture-config` that might have implicitly relied on `path.py` objects, migrating to `pathlib.Path` objects.
affects: >=1.8.0
gotchaEnsure your `pytest-fixture-config` plugin is discoverable by pytest. It must be installed in the environment where pytest runs, or explicitly enabled if not using setuptools entry points.
fix
Verify `pip install pytest-fixture-config` completed successfully. If using a `conftest.py`, ensure `pytest_plugins = ['pytest_fixture_config']` is present if auto-discovery fails.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_fixture_config'
The `pytest-fixture-config` package is not installed or not accessible in the current Python environment.
fix
Run `pip install pytest-fixture-config` to install the package.
pytest.FixtureNotFound: Fixture 'my_config_fixture' not found
A test or another fixture is requesting a fixture that either isn't defined, is misspelled, or isn't discoverable by pytest (e.g., in a `conftest.py` that's out of scope).
fix
Check the spelling of the fixture name, ensure the fixture is defined within a `conftest.py` in an appropriate directory, or explicitly imported if it's not a root-level plugin fixture. If using `pytest_plugins = ['pytest_fixture_config']`, verify it's correctly specified.
AttributeError: 'MyAppConfig' object has no attribute 'new_attribute'
You are attempting to access an attribute on a `Config` subclass instance that was not declared in its `__slots__` attribute.
fix
Add the 'new_attribute' to the `__slots__` tuple in your `MyAppConfig` class definition. Remember that classes using `__slots__` do not support dynamic attribute assignment outside of the defined slots.
Upgrade
Version history
1.8.0latest on PyPI · released Oct 17, 2024
Audit
Dependencies
pytestrequiredThis is a pytest plugin and requires pytest to function.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
Bingbot
1
Resources
pytest-fixture-config — pip install pytest-fixture-config · libregistry