Skip to content

Instantly share code, notes, and snippets.

@cjw296
Created February 16, 2017 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjw296/82a9fd25a91456231fcdef432e8a9978 to your computer and use it in GitHub Desktop.
Save cjw296/82a9fd25a91456231fcdef432e8a9978 to your computer and use it in GitHub Desktop.
____________________________________________________________________________________________ test_compare_fail_for_pytest _____________________________________________________________________________________________
def test_compare_fail_for_pytest():
> compare({'x': 1}, {'x': 2})
testfixtures/tests/test_compare.py:1379:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
args = ({'x': 1}, {'x': 2}), kw = {}, prefix = None, suffix = None, raises = True, context = <testfixtures.comparison.CompareContext object at 0x103f5cdd8>, x = {'x': 1}, y = {'x': 2}
message = "dict not as expected:\n\nvalues differ:\n'x': 1 != 2"
def compare(*args, **kw):
"""
Compare the two arguments passed either positionally or using
explicit ``expected`` and ``actual`` keyword paramaters. An
:class:`AssertionError` will be raised if they are not the same.
The :class:`AssertionError` raised will attempt to provide
descriptions of the differences found.
Any other keyword parameters supplied will be passed to the functions
that end up doing the comparison. See the API documentation below
for details of these.
:param prefix: If provided, in the event of an :class:`AssertionError`
being raised, the prefix supplied will be prepended to the
message in the :class:`AssertionError`.
:param suffix: If provided, in the event of an :class:`AssertionError`
being raised, the suffix supplied will be appended to the
message in the :class:`AssertionError`.
:param raises: If ``False``, the message that would be raised in the
:class:`AssertionError` will be returned instead of the
exception being raised.
:param recursive: If ``True``, when a difference is found in a
nested data structure, attempt to highlight the location
of the difference.
:param strict: If ``True``, objects will only compare equal if they are
of the same type as well as being equal.
:param ignore_eq: If ``True``, object equality, which relies on ``__eq__``
being correctly implemented, will not be used.
Instead, comparers will be looked up and used
and, if no suitable comparer is found, objects will
be considered equal if their hash is equal.
:param comparers: If supplied, should be a dictionary mapping
types to comparer functions for those types. These will
be added to the global comparer registry for the duration
of this call.
"""
prefix = kw.pop('prefix', None)
suffix = kw.pop('suffix', None)
raises = kw.pop('raises', True)
context = CompareContext(kw)
x, y = context.extract_args(args)
if not context.different(x, y, not_there):
return
message = context.message
if prefix:
message = prefix + ': ' + message
if suffix:
message += '\n' + suffix
if raises:
> raise AssertionError(message)
E AssertionError: dict not as expected:
E
E values differ:
E 'x': 1 != 2
testfixtures/comparison.py:481: AssertionError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment