{"id":8529,"library":"pytest-fixture-config","title":"pytest-fixture-config","description":"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.","status":"active","version":"1.8.0","language":"en","source_language":"en","source_url":"https://github.com/man-group/pytest-plugins","tags":["pytest","testing","fixtures","configuration","plugin"],"install":[{"cmd":"pip install pytest-fixture-config","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This is a pytest plugin and requires pytest to function.","package":"pytest","optional":false}],"imports":[{"symbol":"Config","correct":"from pytest_fixture_config import Config"},{"symbol":"requires_config","correct":"from pytest_fixture_config import requires_config"},{"symbol":"yield_requires_config","correct":"from pytest_fixture_config import yield_requires_config"}],"quickstart":{"code":"import os\nimport pytest\nimport subprocess\nfrom pytest_fixture_config import Config, requires_config\n\n# 1. Define your configuration class inheriting from Config\nclass MyAppConfig(Config):\n    __slots__ = ('api_key', 'base_url') # Define expected config attributes\n\n# 2. Create a singleton instance, reading from environment variables\nAPP_CONFIG = MyAppConfig(\n    api_key=os.environ.get('MY_APP_API_KEY'), # No default, required\n    base_url=os.environ.get('MY_APP_BASE_URL', 'https://api.example.com') # With default\n)\n\n# 3. Use requires_config decorator to make fixtures dependent on config\n@pytest.fixture\n@requires_config(APP_CONFIG, ['api_key'])\ndef authenticated_client():\n    \"\"\"Provides an authenticated client if API_KEY is set.\"\"\"\n    print(f\"\\nUsing API Key: {APP_CONFIG.api_key[:5]}... and Base URL: {APP_CONFIG.base_url}\")\n    # In a real app, this would initialize an API client\n    class MockClient:\n        def fetch_data(self): return {\"status\": \"data_fetched\"}\n    return MockClient()\n\ndef test_data_fetch(authenticated_client):\n    \"\"\"This test requires a valid API_KEY to run.\"\"\"\n    assert authenticated_client.fetch_data() == {\"status\": \"data_fetched\"}\n\n# To run this example:\n# 1. Save as `test_app.py`\n# 2. Run: `pytest -s test_app.py` (it will be skipped)\n# 3. Set env var: `export MY_APP_API_KEY=\"your_secret_key\"`\n# 4. Run again: `pytest -s test_app.py` (it should pass)","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to version 3.6 or newer.","message":"Python 2 and Python <3.6 support has been dropped. All compatibility code for older Python versions was removed in v1.8.0.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Update any code directly importing or relying on the standalone `mock` package to use `unittest.mock` instead.","message":"The `mock` package is no longer used. All mock-related functionality now uses the standard library's `unittest.mock` module.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Refactor any code interacting with `pytest-fixture-config` that might have implicitly relied on `path.py` objects, migrating to `pathlib.Path` objects.","message":"Usage of `path.py` and `path` has been removed in favor of `pathlib` for file system path operations.","severity":"breaking","affected_versions":">=1.8.0"},{"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.","message":"Ensure 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install pytest-fixture-config` to install the package.","cause":"The `pytest-fixture-config` package is not installed or not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'pytest_fixture_config'"},{"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.","cause":"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).","error":"pytest.FixtureNotFound: Fixture 'my_config_fixture' not found"},{"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.","cause":"You are attempting to access an attribute on a `Config` subclass instance that was not declared in its `__slots__` attribute.","error":"AttributeError: 'MyAppConfig' object has no attribute 'new_attribute'"}]}