Skip to content

test: assert Field.make_error kwargs interpolation and Tuple partial valid_data - #3105

Draft
janmejai2002 wants to merge 1 commit into
marshmallow-code:devfrom
janmejai2002:test/field-make-error-and-tuple-valid-data
Draft

janmejai2002 wants to merge 1 commit into
marshmallow-code:devfrom
janmejai2002:test/field-make-error-and-tuple-valid-data

Conversation

@janmejai2002

Copy link
Copy Markdown

Summary

This PR adds unit test coverage for two subtle behavioral contracts in marshmallow.fields:

  1. Field.make_error(**kwargs) formatting interpolation:

    • Field.make_error is designed to format error message templates with keyword arguments via msg.format(**kwargs).
    • Existing unit tests in tests/test_fields.py only exercised field.make_error(key) with static strings and without kwargs, leaving template parameter substitution unasserted.
    • Adds test_make_error_with_formatting_kwargs to verify that passing keyword arguments (e.g. field.make_error("formatted", field_name="age", min_val=18)) properly interpolates placeholders into the resulting ValidationError message.
  2. Tuple partial valid_data retention on deserialization failure:

    • When a Tuple field encounters deserialization failures in one or more elements, it collects validly parsed elements into ValidationError.valid_data (raise ValidationError(errors, valid_data=result)).
    • Existing tests in tests/test_deserialization.py verified the error dictionary (exc.messages), but did not assert exc.valid_data.
    • Adds assertions verifying that:
      • Leading valid elements followed by invalid elements correctly populate exc.valid_data == ["good"].
      • Leading invalid elements followed by valid elements correctly populate exc.valid_data == ["good"] without inserting premature None entries.

Verification

  • Tests: Ran pytest tests/test_fields.py tests/test_deserialization.py -q: 507 passed in 0.85s (0 failures).
  • Linter: Ran ruff check and ruff format --check: all checks passed, 0 errors.
  • Mocks: 0 synthetic mocks; tests use native fields.Tuple, fields.Integer, fields.Str, and real ValidationError instances.

@lafrech

lafrech commented Nov 11, 2026

Copy link
Copy Markdown
Member

Not sure the latter is intended (#201340).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants