cubicweb/server/test/unittest_rql2sql.py
changeset 11771 96a8ad81317b
parent 11770 22b854d3e8b2
child 11775 39cf9e55ada8
--- a/cubicweb/server/test/unittest_rql2sql.py	Thu Oct 06 21:17:01 2016 +0200
+++ b/cubicweb/server/test/unittest_rql2sql.py	Mon Oct 17 13:42:30 2016 +0200
@@ -23,13 +23,29 @@
 
 from logilab import database as db
 from logilab.common.testlib import mock_object
+from logilab.common.decorators import monkeypatch
 
 from rql import BadRQLQuery
 from rql.utils import register_function, FunctionDescr
 
 from cubicweb import devtools
 from cubicweb.devtools.repotest import RQLGeneratorTC
-from cubicweb.server.sources.rql2sql import remove_unused_solutions
+from cubicweb.server.sources.rql2sql import SQLGenerator, remove_unused_solutions
+
+
+def setUpModule():
+    """Monkey-patch the SQL generator to ensure solutions order is predictable."""
+    global orig_solutions_sql
+    orig_solutions_sql = SQLGenerator._solutions_sql
+
+    @monkeypatch
+    def _solutions_sql(self, select, solutions, distinct, needalias):
+        return orig_solutions_sql(self, select, sorted(solutions), distinct, needalias)
+
+
+def tearDownModule():
+    """Remove monkey-patch done in setUpModule"""
+    SQLGenerator._solutions_sql = orig_solutions_sql
 
 
 # add a dumb registered procedure