Skip to content

Better diff for asserts on dicts #1531

@SuperDoxin

Description

@SuperDoxin

Currently in some edge cases py.test returns utterly useless diffs for asserts on dicts, it doesn't provide the context needed to find which parts are differing in deeply nested dicts.

A better, and simpler, solution would be to use a json serializer to serialize the dicts and then use difflibs unified diff to generate the final diff. this solution will produce a diff in an easy to read format that people are familiar with and provides enough context to find the right place in the dict where changes need to be made.

any objects not json serializable in the dict can be adequately dealt with by using repr as serializer.

this whole function could be replaced with ~5 lines of code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions