Skip to content

Fix output_verbosity Literal to accept int values for unittest tester - #733

Merged
david-yz-liu merged 4 commits into
MarkUsProject:masterfrom
donny-wong:fix_py_tester_output_verbosity_schema
Jul 2, 2026
Merged

Fix output_verbosity Literal to accept int values for unittest tester#733
david-yz-liu merged 4 commits into
MarkUsProject:masterfrom
donny-wong:fix_py_tester_output_verbosity_schema

Conversation

@donny-wong

@donny-wong donny-wong commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Problem

output_verbosity in PyTestData (shared by the pytest and unittest testers) was typed as a string-only Literal. The unittest tester uses integer verbosity levels (0/1/2, matching Python's unittest), and the MarkUs form already emits these ints — the manually patched JSON Schema enum allowed them. But the Struct type did not, so msgspec would reject an int-valued output_verbosity on decode.

We don't currently decode tester configs with msgspec (we read them as plain dicts), so nothing is breaking today. This aligns the type with the data and the already-patched schema so we're ready if/when we adopt msgspec decoding.

Fix

Adding the ints as a single mixed Literal[..., 0, 1, 2] isn't viable: msgspec.json.schema_components sorts Literal values to build the enum, and sorting mixed int/str raises TypeError: '<' not supported between instances of 'int' and 'str', breaking schema generation. So output_verbosity is now a union of two same-typed Literals:

pythonLiteral["", "short", "auto", "long", "no", "line", "native"] | Literal[0, 1, 2]

msgspec emits this as an anyOf of two enums. In settings(), the old hardcoded enum patch is replaced with a step that flattens that anyOf into a single flat enum, which is the shape the form (rjsf) expects. The allowed values now live in the type and drive both validation and the generated schema, rather than a separately maintained hardcoded list.

@donny-wong
donny-wong marked this pull request as ready for review June 28, 2026 14:44
@donny-wong
donny-wong requested a review from Naragod June 28, 2026 14:47
@Naragod
Naragod requested a review from david-yz-liu July 2, 2026 15:00

@david-yz-liu david-yz-liu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @donny-wong!

@david-yz-liu
david-yz-liu merged commit a35febd into MarkUsProject:master Jul 2, 2026
8 checks passed
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.

3 participants