Skip to content

Fix serialization of str subclasses in subtest msg parameter - #15134

Open
RonnyPfannschmidt wants to merge 1 commit into
mainfrom
claude/project-thread-pe7mtw
Open

RonnyPfannschmidt wants to merge 1 commit into
mainfrom
claude/project-thread-pe7mtw

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Requested by Ronny · project thread

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

Reports must be serializable, so the report producer is responsible for handing over plain data. SubtestContext already does this for kwargs (#13963), and TestCase.subTest converts its message (#14196). The native subtests.test(msg=...) path did not: a str subclass such as a StrEnum member stayed on the report, and pytest-xdist failed with DumpError: can't serialize <enum ...>.

SubtestContext now converts str subclasses to plain str via str.__str__, which keeps the string data (str() on a (str, Enum) mixin would yield "Cls.MEMBER").

Fixes pytest-dev/pytest-xdist#1161, in place of the xdist-side workaround in pytest-dev/pytest-xdist#1389.

🤖 Generated with Claude Code

https://claude.ai/code/session_014AXM2385U5x4VaR1ppeo4X

RonnyPfannschmidt pushed a commit that referenced this pull request Oct 5, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014AXM2385U5x4VaR1ppeo4X
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 5, 2026
@RonnyPfannschmidt RonnyPfannschmidt self-assigned this Oct 5, 2026
A str subclass passed as the subtest msg, such as a StrEnum member,
was stored on the report as-is. execnet serializes by exact type, so
pytest-xdist failed with "DumpError: can't serialize <enum ...>".

Convert such messages with str.__str__ in SubtestContext, next to the
existing saferepr handling of kwargs. str.__str__ keeps the string data;
str() on a (str, Enum) mixin would give "Cls.MEMBER".

Refs pytest-dev/pytest-xdist#1161.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014AXM2385U5x4VaR1ppeo4X

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serialization error with StrEnum obj

2 participants