Deep Diff

Usage of Deep Diff in API Testing.

ยท

1 min read

Table of contents

No heading

No headings in the article.

Installation: pip install deepdiff

Usage: from deepdiff import DeepDiff

Official Link: https://pypi.org/project/deepdiff/

Docs: https://zepworks.com/deepdiff/5.8.1/

DeepDiff helps me a lot in QA space, especially in API Testing. In the below example, DeepDiff class takes in two arguments, i.e. two dictionaries, one with expected input and one with the actual output, And returns an DeepDiff object.

expected = {1:1, 2:2, 3:3}
actual = {1:1, 2:3, 3:3}

def deepDiff():
    changes = DeepDiff(expected, actual)
    print('Type {}'.format(type(changes)))
    print('Changes {}'.format(changes))

deepDiff()

Output is shown in the below screenshot. We can print the changes and see the difference:

Changes {'values_changed': {'root[2]': {'new_value': 3, 'old_value': 2}}}

image.png