pytest-dev / pytest-dev/pytest
Proposal: fixture-owned notes via request.add_note (refine #1376)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
What's the problem this feature will solve?
Refines / supersedes #1376.
Fixtures often know useful context (DB paths, hosts, ports, etc.). Printing it loses that context in captured output. There is no first-class way for a fixture to attach notes that:
- belong to the fixture instance (including higher scopes),
- are available to every dependent test that uses that instance,
- show cleanly on failure without pass-path noise,
- are available to report consumers (
TestReport, reportlog, etc.).
Item-local escapes (print, add_report_section, user_properties) do not model scoped fixture ownership.
Describe the solution you'd like
API
@pytest.fixture(scope="session")
def db(request):
path = mk_db()
request.add_note(f"db path: {path}")
request.add_note({"path": str(path), "engine": "sqlite"})
yield path
def add_note(self, note: str | dict[str, str]) -> None: ...
- Named like
BaseException.add_note. - Calls append;
strordict[str, str]in v1. - Notes are owned by the fixture instance / its scope, not by the requesting item.
Behavior
- Notes are projected into test reports for dependents of that fixture instance (including passes, for tooling).
- Terminal shows them only on failure.
- Higher-scope notes appear on every dependent test report by design.
- Later: keep room for richer note payloads; not required in v1.
Out of scope
- First-class fixture report nodes / reworking setup-teardown attribution.
- Skipping dependents when a scoped fixture fails.
- Showing notes on passing tests in the terminal.
- Rich renderable public API in v1.
Alternative Solutions
print/ logging — unstructured, lost in capture.add_report_section/user_properties— item-local; wrong owner for scoped fixtures.- Original #1376
add_info_on_failureonly — too narrow for fixture-owned notes shared across dependents.
Additional context
Related: #1376. Intentional split: Holger’s failure-context need, plus fixture-owned notes visible to all dependents; larger fixture-report-node work stays separate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation file or test is named. Start by tracing the fixture request API and the report consumers mentioned in the proposal, then determine how fixture-instance ownership and scope interact with dependent reports. Done means supporting string and dictionary notes, exposing them to report consumers, showing them only on terminal failures, and preserving the listed out-of-scope behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100