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.
pip install pytest-describeVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
To use custom prefixes, add a configuration like this to your `pyproject.toml`: `[tool.pytest.ini_options] describe_prefixes = ["describe_", "context_", "feature_"]`. Without this, only `describe_` blocks will be collected.
Add 'from pytest_describe import describe, it' at the top of your test file.
Install the package using pip: `pip install pytest-describe`
Provide a descriptive string as the first argument, e.g., `describe("My feature under test", ...)` or `it("should do something specific", ...)`.Declare the fixture as an argument in the 'it' or 'before_each' function signature, e.g., `it("should use fixture", lambda my_fixture: ...)` or `def before_each(my_fixture): ...`.