Browse files

Allowed a message to be passed to assertQuerysetEqual to make it cons…

…istent with other assert methods.
  • Loading branch information...
1 parent 21f0341 commit c5395eef7693e1ae222cbfd81d031237c1802c7f @chrispbailey chrispbailey committed with timgraham Feb 10, 2014
Showing with 11 additions and 4 deletions.
  1. +3 −3 django/test/
  2. +8 −1 docs/topics/testing/tools.txt
@@ -825,17 +825,17 @@ def _fixture_teardown(self):
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 =, 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)
@@ -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,13 +1456,20 @@ 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``
if undefined order is spotted. The ordering is seen as undefined if
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

0 comments on commit c5395ee

Please sign in to comment.