An ideal situation is to use predictable test interfaces. Hence ideally you
should have sequence of inserts and updates and selects at end of which you
should be able to verify that database logic is consistent with your
expectations.
But if random records query is a requirement, at outset you can
from sqlalchemy.sql.expression import func
random_row = session.query(YourModel).order_by(func.random()).first()
this is equivalent to:
SELECT * FROM my_table ORDER BY RAND() LIMIT 1;
http://www.kavoir.com/2009/03/sql-randomly-shuffle-rows-or-records-reorder-them-in-a-random-order.html
I have not