Upon request of the auditor or treasurer, the district attorney shall defend or prosecute any action brought by or against the auditor or treasurer for the purpose of testing the validity or constitutionality of any act of the Legislature or of the board of supervisors or of any order providing for the payment of any funds held in the county treasury in those cases only where the interest of the county is not adverse.