Skip to main content

Better testing with expecter and pytest.

Project description

pytest-expecter

This is a fork of garybernhardt/expecter that hides the internal stack trace for pytest.

Build Status
PyPI Version

Overview

This lets you write tests (using ropez/pytest-describe) like this:

from expecter import expect


def describe_foobar():

    def it_can_pass():
        expect(2 + 3) == 5

    def it_can_fail():
        expect(2 + 3) == 6

and instead of getting output like this:

=================================== FAILURES ===================================
_________________________ describe_foobar.it_can_fail __________________________

    def it_can_fail():
>       expect(2 + 3) == 6

test_foobar.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = expect(5), other = 6

    def __eq__(self, other):
        msg = 'Expected %s but got %s' % (repr(other), repr(self._actual))
        if (isinstance(other, basestring) and
                isinstance(self._actual, basestring)):
            msg += normalized_diff(other, self._actual)
        elif len(repr(self._actual)) > 74:
            msg += normalized_diff(pprint.pformat(other),
                                   pprint.pformat(self._actual))
>       assert self._actual == other, msg
E       AssertionError: Expected 6 but got 5

env/lib/python3.5/site-packages/expecter.py:57: AssertionError
====================== 1 failed, 1 passed in 2.67 seconds ======================

getting output like this:

=================================== FAILURES ===================================
_________________________ describe_foobar.it_can_fail __________________________

    def it_can_fail():
>       expect(2 + 3) == 6
E       AssertionError: Expected 6 but got 5

test_foobar.py:14: AssertionError
====================== 1 failed, 1 passed in 2.67 seconds ======================

Installation

pip install pytest-expecter

Revision History

1.1 (unreleased)

  • Add expect fixture to use directly in tests.

1.0 (2017/12/03)

  • Initial stable release.

0.2.2.post7 (2017/12/02)

  • Added automatic conversion from OrderedDict to dict on Python 3.6 to create readable diffs.

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-expecter-1.1b1.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

pytest_expecter-1.1b1-py2-none-any.whl (15.1 kB view hashes)

Uploaded Python 2

Supported by

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