Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…istent with other assert methods.
  • Loading branch information...
commit c5395eef7693e1ae222cbfd81d031237c1802c7f 1 parent 21f0341
Chris Bailey chrispbailey authored timgraham committed
Showing with 11 additions and 4 deletions.
  1. +3 −3 django/test/testcases.py
  2. +8 −1 docs/topics/testing/tools.txt
6 django/test/testcases.py
View
@@ -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 = 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)
9 docs/topics/testing/tools.txt
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.