{"id":5425,"library":"pytest-describe","title":"pytest-describe","description":"pytest-describe is a plugin for the pytest testing framework that enables writing tests in an RSpec/Jasmine-style format, using arbitrary nested `describe-blocks`. This approach helps organize tests by context and behavior, making test suites more readable and maintainable. The current version is 3.1.0, and it is actively maintained with regular updates to support newer Python and pytest versions.","status":"active","version":"3.1.0","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-describe","tags":["pytest","testing","plugin","bdd","describe"],"install":[{"cmd":"pip install pytest-describe","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"pytest-describe is a plugin for pytest and requires pytest to function.","package":"pytest","optional":false}],"imports":[{"note":"Used for sharing test behaviors across multiple describe blocks.","symbol":"behaves_like","correct":"from pytest_describe import behaves_like"},{"note":"Core describe/it functionality relies on specific function naming conventions (`describe_`, `it_`) within test modules and does not require explicit imports into user code. These names are automatically discovered by pytest with the plugin active.","symbol":"describe_ / it_ (naming conventions)","correct":"def describe_feature():\n    def it_should_do_something():\n        pass"}],"quickstart":{"code":"import pytest\n\nclass Wallet:\n    def __init__(self, initial_amount=0):\n        self.balance = initial_amount\n\n    def spend_cash(self, amount):\n        if self.balance < amount:\n            raise ValueError(f'Not enough available to spend {amount}')\n        self.balance -= amount\n\n    def add_cash(self, amount):\n        self.balance += amount\n\ndef describe_wallet():\n    def describe_start_empty():\n        @pytest.fixture\n        def wallet():\n            return Wallet()\n\n        def initial_amount_is_zero(wallet):\n            assert wallet.balance == 0\n\n        def can_add_cash(wallet):\n            wallet.add_cash(80)\n            assert wallet.balance == 80\n\n        def cannot_spend_if_empty(wallet):\n            with pytest.raises(ValueError):\n                wallet.spend_cash(10)\n\n    def describe_with_starting_balance():\n        @pytest.fixture\n        def wallet():\n            return Wallet(20)\n\n        def initial_amount_is_twenty(wallet):\n            assert wallet.balance == 20\n\n        def describe_adding():\n            def add_little_cash(wallet):\n                wallet.add_cash(5)\n                assert wallet.balance == 25\n\n            def add_much_cash(wallet):\n                wallet.add_cash(980)\n                assert wallet.balance == 1000\n\n        def describe_spending():\n            def spend_cash(wallet):\n                wallet.spend_cash(15)\n                assert wallet.balance == 5\n\n            def spend_too_much_cash(wallet):\n                with pytest.raises(ValueError):\n                    wallet.spend_cash(25)","lang":"python","description":"This example demonstrates how to structure tests for a `Wallet` class using nested `describe_` blocks and `pytest` fixtures. Define a top-level `describe_` function, and then nest further `describe_` functions or test functions (which can also use the `it_` prefix) within them. Fixtures defined within a `describe_` block apply to all tests within that block and its nested blocks. Save this as a Python file (e.g., `test_wallet.py`) and run `pytest` from your terminal."},"warnings":[{"fix":"Always check the `pytest-describe` release notes or documentation for the supported `pytest` and `Python` versions before upgrading your testing environment. If compatibility issues arise, downgrade `pytest-describe` or `pytest` to a compatible version.","message":"pytest-describe versions are tightly coupled to specific ranges of pytest and Python versions. For instance, version 3.1.0 supports pytest 6.0 to 9.0 and Python 3.9 to 3.14. Upgrading your pytest or Python environment without verifying compatibility against pytest-describe's release notes can lead to unexpected test collection failures or runtime errors.","severity":"breaking","affected_versions":"<3.1.0, >=2.0.0"},{"fix":"Ensure that all functions intended to be tests within `describe_` blocks follow the standard pytest naming conventions (e.g., `test_`, or for `pytest-describe`, commonly `it_` or other non-underscore prefixed names like `initial_amount_is_zero`) to ensure they are discovered and run.","message":"Within `describe_` blocks, only functions starting with `describe_` or any non-underscore prefix are collected as tests. Functions that start with a single underscore (e.g., `def _helper_function():`) are explicitly *not* collected as tests. This is intended for helper functions but can be a gotcha if you accidentally prefix a test with an underscore, causing it to be skipped.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To use custom prefixes, add a configuration like this to your `pyproject.toml`: `[tool.pytest.ini_options]\ndescribe_prefixes = [\"describe_\", \"context_\", \"feature_\"]`. Without this, only `describe_` blocks will be collected.","message":"By default, `pytest-describe` only recognizes functions starting with `describe_` as test blocks. If you prefer to use alternative prefixes (e.g., `context_`, `feature_`) for your organizational blocks, you must explicitly configure these in your pytest configuration file (e.g., `pyproject.toml` or `pytest.ini`) using the `describe_prefixes` option.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}