# HG changeset patch # User Sylvain Thénault # Date 1476704550 -7200 # Node ID 96a8ad81317ba8206e3c13fb1488d1e995eaee4e # Parent 22b854d3e8b2047260df16f733696fd359630c05 [rql2sql/test] Ensure test results predictability Without this, test were randomly failing within tox due to different order of solutions. diff -r 22b854d3e8b2 -r 96a8ad81317b cubicweb/server/test/unittest_rql2sql.py --- 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