def test_count(self):

        User, users = self.classes.User, self.tables.users

        mapper(User, users)

        session = create_session()
        q = session.query(User)

        eq_(q.count(), 4)
        eq_(q.filter(User.id.in_([8, 9])).count(), 2)
        eq_(q.filter(users.c.id.in_([8, 9])).count(), 2)

        eq_(session.query(User.id).count(), 4)
        eq_(session.query(User.id).filter(User.id.in_((8, 9))).count(), 2)
The count function on Query.
dataset/ETHPy150Open zzzeek/sqlalchemy/test/orm/test_mapper.py/MapperTest.test_count