Prepared statement parameters can only be used where SQL allows expressions. Table names are not expressions, they have to be literals in the query. You can use string formatting to substitute into the string.
trunc_table = "truncate table %s" % table_name
cur.execute(trunc_table)
Also, I think you need to use a different cursor to execute the second query while you're looping through the results of the first query. So before the loop, do:
cur2 = connection.cursor()
cur2.execute("USE Test")
and then use
cur2.execute(trunc_table)
in the loop. Another option would be to use cur.fetchall()
to get all the rows first, then you can reuse the cursor.
for (table_name,) in cur.fetchall():