Skip to content

Expose describe functions and use docstrings as block names#55

Merged
Cito merged 1 commit into
mainfrom
describe-reporting
Jun 12, 2026
Merged

Expose describe functions and use docstrings as block names#55
Cito merged 1 commit into
mainfrom
describe-reporting

Conversation

@Cito

@Cito Cito commented Jun 12, 2026

Copy link
Copy Markdown
Member

What's changing

This PR adds two closely related features for better test reporting:

Public API: get_describe_functions(item)

A new public function exported from pytest_describe that returns the describe functions enclosing a collected test item, starting with the outermost block. Reporting plugins (e.g. pytest-spec) can use it to access the original describe functions and their docstrings.

This supersedes #53 — many thanks to @joshuaprior for the original proposal and the pytest-spec integration. The implementation here uses a simple documented helper based on item.listchain() instead of attaching methods to the items at collection time.

Opt-in docstring names for describe blocks

A new boolean ini option describe_docstrings (default: off). When enabled, describe blocks that have a docstring are reported under the first line of that docstring instead of the function name:

test_wallet.py::a wallet::when it is empty::it_has_no_balance PASSED

This implements the suggestion of @undeadgrishnackh in #41. The option is opt-in because the names become part of the node IDs, which would otherwise change for existing test suites that happen to have docstrings.

Closes #41, closes #53.

Both features are covered by new tests and documented in the README.

🤖 Generated with Claude Code

Add a public function get_describe_functions() so that reporting
plugins can access the describe functions enclosing a test item,
and an opt-in ini option describe_docstrings that uses docstrings
as names for describe blocks in test reports.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Cito Cito merged commit 23aed77 into main Jun 12, 2026
8 checks passed
@Cito Cito deleted the describe-reporting branch June 12, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement] use a DocString to enhance the test report description

1 participant