Skip to main content

A simple plugin to use with pytest

Project description

PyPI version Python versions See Build Status on Travis CI See Build Status on AppVeyor

A simple plugin to use with pytest


This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Features

  • Readable diffs for failed tests

  • Customizable diffs for your classes

Requirements

  • pytest

  • deepdiff

  • pprintpp

Installation

You can install “pytest-diff” via pip from PyPI:

$ pip install pytest-diff

Usage

class Person:
    def __init__(self, name, age, favorites):
        self.name = name
        self.age = age
        self.favorites = favorites


def test_person():
    a = Person("Alice", age=21, favorites={"food": "spam", "movie": "Life of Brian"})
    b = Person("Alice", age=21, favorites={"food": "eggs", "movie": "Life of Brian"})
    assert a == b

Running pytest gives:

______________________________ test_person ______________________________

    def test_person():
        a = Person("Alice", age=21, favorites={'food': 'spam', 'movie': 'Life of Brian'})
        b = Person("Alice", age=21, favorites={'food': 'eggs', 'movie': 'Life of Brian'})
>       assert a == b
E       assert
E         <test_person.Person object at 0x7fa326d769e8>
E         ==
E         <test_person.Person object at 0x7fa326d76be0>
E         {'values_changed': {"root.favorites['food']": {'new_value': 'spam', 'old_value': 'eggs'}}}

examples/test_person.py:11: AssertionError

To customize diffs for a specific type:

import pytest_diff

from tests import utils

@pytest_diff.dispatcher.dispatch
def diff(x: utils.Container, y: utils.Container):
    return  ["My custom diff", "has multiple lines."]

def test_container_unequal():
     c1 = utils.Container(["a", "b"])
     c2 = utils.Container(["d", "e", "f"])
     assert c1 == c2

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-diff” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-diff-0.1.8.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_diff-0.1.8-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest-diff-0.1.8.tar.gz.

File metadata

  • Download URL: pytest-diff-0.1.8.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pytest-diff-0.1.8.tar.gz
Algorithm Hash digest
SHA256 0c230956c153149a28edc9ce807a7c732b60d36e526be7915b23d93a6e51883c
MD5 f14197bf56dab9e1683aca41f0ea5099
BLAKE2b-256 d8d479111b70e10054ab7f96c5685405068bb41bb5df4683b0ed9b2571037076

See more details on using hashes here.

File details

Details for the file pytest_diff-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pytest_diff-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pytest_diff-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a6994276e46473b5a13a35b6476ce8104572d7500ba4e5d8141be803ff0095d0
MD5 7be4b1f2b9f324a6ce7f698b5298ebdb
BLAKE2b-256 6075ae676c2c753443202a47dc3d27f1d706123c435a2a38f16a877024118b5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page