From c5395eef7693e1ae222cbfd81d031237c1802c7f Mon Sep 17 00:00:00 2001 From: Chris Bailey Date: Mon, 10 Feb 2014 05:18:20 -0500 Subject: [PATCH] Allowed a message to be passed to assertQuerysetEqual to make it consistent with other assert methods. --- django/test/testcases.py | 6 +++--- docs/topics/testing/tools.txt | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 4a44a171bc..2764fc0886 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -825,17 +825,17 @@ class TransactionTestCase(SimpleTestCase): allow_cascade=self.available_apps is not None, inhibit_post_migrate=self.available_apps is not None) - def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True): + def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True, msg=None): items = six.moves.map(transform, qs) if not ordered: - return self.assertEqual(set(items), set(values)) + return self.assertEqual(set(items), set(values), msg=msg) values = list(values) # For example qs.iterator() could be passed as qs, but it does not # have 'ordered' attribute. if len(values) > 1 and hasattr(qs, 'ordered') and not qs.ordered: raise ValueError("Trying to compare non-ordered queryset " "against more than one ordered values") - return self.assertEqual(list(items), values) + return self.assertEqual(list(items), values, msg=msg) def assertNumQueries(self, num, func=None, *args, **kwargs): using = kwargs.pop("using", DEFAULT_DB_ALIAS) diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 49d4c10bbb..e31021eaef 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -1443,7 +1443,7 @@ your test suite. Output in case of error can be customized with the ``msg`` argument. -.. method:: TransactionTestCase.assertQuerysetEqual(qs, values, transform=repr, ordered=True) +.. method:: TransactionTestCase.assertQuerysetEqual(qs, values, transform=repr, ordered=True, msg=None) Asserts that a queryset ``qs`` returns a particular list of values ``values``. @@ -1456,6 +1456,8 @@ your test suite. provide an implicit ordering, you can set the ``ordered`` parameter to ``False``, which turns the comparison into a Python set comparison. + Output in case of error can be customized with the ``msg`` argument. + .. versionchanged:: 1.6 The method now checks for undefined order and raises ``ValueError`` @@ -1463,6 +1465,11 @@ your test suite. the given ``qs`` isn't ordered and the comparison is against more than one ordered values. + .. versionchanged:: 1.7 + + The method now accepts a ``msg`` parameter to allow customization of + error message + .. method:: TransactionTestCase.assertNumQueries(num, func, *args, **kwargs) Asserts that when ``func`` is called with ``*args`` and ``**kwargs`` that