Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Traceback Messages Are Very Verbose Using Assetpy in Pytest #100

Copy link
Copy link
@iandonnelly

Description

@iandonnelly
Issue body actions

When an assertion using assertpy fails, the traceback message is too verbose and makes viewing the error needlessly difficult.

Here is an example:


run_command = <subprocess.Popen object at 0x7f7f63126518>

    def test_exit_code(run_command):
        test_result = run_command.communicate()[0]
        exit_code = run_command.returncode
        # if exit_code != 0:
        #     with open('{}_comparison.txt'.format(current_writer), 'wb') as result_file:
        #         result_file.write(test_result)
>       assert_that(exit_code, "The results did not match").is_equal_to(0)

mytest.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <assertpy.assertpy.AssertionBuilder object at 0x7f7f631265c0>, other = 0, kwargs = {}

    def is_equal_to(self, other, **kwargs):
        """Asserts that val is equal to other.
    
        Checks actual is equal to expected using the ``==`` operator. When val is *dict-like*,
        optionally ignore or include keys when checking equality.
    
        Args:
            other: the expected value
            **kwargs: see below
    
        Keyword Args:
            ignore: the dict key (or list of keys) to ignore
            include: the dict key (of list of keys) to include
    
        Examples:
            Usage::
    
                assert_that(1 + 2).is_equal_to(3)
                assert_that('foo').is_equal_to('foo')
                assert_that(123).is_equal_to(123)
                assert_that(123.4).is_equal_to(123.4)
                assert_that(['a', 'b']).is_equal_to(['a', 'b'])
                assert_that((1, 2, 3)).is_equal_to((1, 2, 3))
                assert_that({'a': 1, 'b': 2}).is_equal_to({'a': 1, 'b': 2})
                assert_that({'a', 'b'}).is_equal_to({'a', 'b'})
    
            When the val is *dict-like*, keys can optionally be *ignored* when checking equality::
    
                # ignore a single key
                assert_that({'a': 1, 'b': 2}).is_equal_to({'a': 1}, ignore='b')
    
                # ignore multiple keys
                assert_that({'a': 1, 'b': 2, 'c': 3}).is_equal_to({'a': 1}, ignore=['b', 'c'])
    
            When the val is *dict-like*, only certain keys can be *included* when checking equality::
    
                # include a single key
                assert_that({'a': 1, 'b': 2}).is_equal_to({'a': 1}, include='a')
    
                # include multiple keys
                assert_that({'a': 1, 'b': 2, 'c': 3}).is_equal_to({'a': 1, 'b': 2}, include=['a', 'b'])
    
            Failure produces a nice error message::
    
                assert_that(1).is_equal_to(2)  # fails
                # Expected <1> to be equal to <2>, but was not.
    
        Returns:
            AssertionBuilder: returns this instance to chain to the next assertion
    
        Raises:
            AssertionError: if actual is **not** equal to expected
    
        Tip:
            Using :meth:`is_equal_to` with a ``float`` val is just asking for trouble. Instead, you'll
            always want to use *fuzzy* numeric assertions like :meth:`~assertpy.numeric.NumericMixin.is_close_to`
            or :meth:`~assertpy.numeric.NumericMixin.is_between`.
    
        See Also:
            :meth:`~assertpy.string.StringMixin.is_equal_to_ignoring_case` - for case-insensitive string equality
        """
        if self._check_dict_like(self.val, check_values=False, return_as_bool=True) and \
                self._check_dict_like(other, check_values=False, return_as_bool=True):
            if self._dict_not_equal(self.val, other, ignore=kwargs.get('ignore'), include=kwargs.get('include')):
                self._dict_err(self.val, other, ignore=kwargs.get('ignore'), include=kwargs.get('include'))
        else:
            if self.val != other:
>               self.error('Expected <%s> to be equal to <%s>, but was not.' % (self.val, other))
E               AssertionError: [The results did not match] Expected <1> to be equal to <0>, but was not.

/home/ian/venv/lib64/python3.6/site-packages/assertpy/base.py:121: AssertionError

Command used to run pytest
pytest mytest.py

Reactions are currently unavailable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.