10BC0 less verbose failure messages · Issue #67 · assertpy/assertpy · GitHub
[go: up one dir, main page]

Skip to content

less verbose failure messages #67

@tekumara

Description

@tekumara

The failure messages I get in pytest are very verbose, and show me the context of the AssertionError inside the assertpy library, which isn't very useful.

Can this be turned down somehow, to be more like the output from the assert statement or hamcrest?

eg:
demo.py

from assertpy import assert_that


def test_demo():
    assert_that(False).is_equal_to(True)

pytest demo.py

================================================
7F71
========= test session starts =========================================================
platform darwin -- Python 3.6.3, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /tmp, inifile:
collected 1 item

demo.py F

============================================================== FAILURES ===============================================================
______________________________________________________________ test_demo ______________________________________________________________

    def test_demo():
>       assert_that(False).is_equal_to(True)

demo.py:5:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../env/lib/python3.6/site-packages/assertpy/assertpy.py:159: in is_equal_to
    self._err('Expected <%s> to be equal to <%s>, but was not.' % (self.val, other))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <assertpy.assertpy.AssertionBuilder object at 0x1099c6588>, msg = 'Expected <False> to be equal to <True>, but was not.'

    def _err(self, msg):
        """Helper to raise an AssertionError, and optionally prepend custom description."""
        out = '%s%s' % ('[%s] ' % self.description if len(self.description) > 0 else '', msg)
        if self.kind == 'warn':
            print(out)
            return self
        elif self.kind == 'soft':
            global _soft_err
            _soft_err.append(out)
            return self
        else:
>           raise AssertionError(out)
E           AssertionError: Expected <False> to be equal to <True>, but was not.

../env/lib/python3.6/site-packages/assertpy/assertpy.py:970: AssertionError
====================================================== 1 failed in 0.11 seconds =======================================================

Vs

demo_assert.py

def test_demo():
    assert False == True

pytest demo_assert.py

========================================================= test session starts =========================================================
platform darwin -- Python 3.6.3, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /tmp, inifile:
collected 1 item

demo_assert.py F

============================================================== FAILURES ===============================================================
______________________________________________________________ test_demo ______________________________________________________________

    def test_demo():
>       assert False == True
E       assert False == True

demo_assert.py:5: AssertionError
====================================================== 1 failed in 0.07 seconds =======================================================

Vs

demo_hamcrest.py

from hamcrest import *

def test_demo():
    assert_that(False, equal_to(True))

pytest demo_hamcrest.py

========================================================= test session starts =========================================================
platform darwin -- Python 3.6.3, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /tmp, inifile:
collected 1 item

demo.py F

============================================================== FAILURES ===============================================================
______________________________________________________________ test_demo ______________________________________________________________

    def test_demo():
        #assert_that(False).is_true()
>       assert_that(False, equal_to(True))
E       AssertionError:
E       Expected: <True>
E            but: was <False>

demo.py:6: AssertionError
====================================================== 1 failed in 0.14 seconds =======================================================

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0