Skip to content

Fix hook tracing with specced mocks - #793

Open
Sandeep1519-droid wants to merge 3 commits into
pytest-dev:mainfrom
Sandeep1519-droid:codex/fix-tracing-proxy-types
Open

Sandeep1519-droid wants to merge 3 commits into
pytest-dev:mainfrom
Sandeep1519-droid:codex/fix-tracing-proxy-types

Conversation

@Sandeep1519-droid

Copy link
Copy Markdown

Fixes #792.

Enabling hook tracing currently makes otherwise successful calls fail when a hook receives Mock(spec=str) or returns Mock(spec=dict) from a first-result hook. These mocks pass isinstance checks for their spec, but their methods do not behave like real strings or dictionaries.

Choose formatting from the actual object type, preserving real subclasses and logging mocks normally.

Validation on Python 3.12.13:

  • Both new regression cases fail on upstream main.
  • uv run pytest — 221 passed with the fix.
  • uv run pre-commit run -a — all hooks passed, including mypy.
  • Changelog entry included.

AI assistance: Codex prepared this fix and its tests at the contributor's request. This draft is awaiting the author's personal review before being marked ready.

Sandeep1519-droid and others added 3 commits October 15, 2026 15:44
Use the actual object type when selecting trace formatting so mocked strings and dictionaries do not interrupt hook execution.

Co-authored-by: Codex <noreply@openai.com>
Both cases fail on upstream main and pass with the tracing fix.

Co-authored-by: Codex <noreply@openai.com>
Fixes pytest-dev#792.

Co-authored-by: Codex <noreply@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook tracing crashes with specced Mock arguments and results

1 participant