id summary reporter owner description type status priority milestone component version severity resolution keywords cc branch changelog apichanges internalchanges 11320 Use a context manager to restore state of functional test environment Ryan J Ollos "There is a repeated pattern of `try` / `finally` in the functional test cases. I started looking at whether we could use a context manager to restore state at the end of each test case. The simplest thing I could think to do for an initial implementation is make a copy of the trac.ini file at the start of test execution, and then restore and reparse it at the end of the test case. With the changes that can be found in log:rjollos.git:t11320, I executed `RegressionTestTicket6747` 100 times before and after making the changes. The execution time was 410 s before the change, and 265 s after. I'm guessing that it's faster because we aren't calling `Configuration.save`. Next I added some code to log back in as //admin// at the end of the test case. It doesn't seem to have measurably affected the execution time on repeated (n = 100) execution of `RegressionTestTicket11028`. If we were to take this further, additional things could be done on entry / exit: * Copy / restore the `permission` table in the database. Another possibility would be to store all of the calls to `grant_perm` and `revoke_perm` and undo the changes. * `FunctionalTestEnvironment.enable_authz_permpolicy / disable_authz_permpolicy`. * Copy / restore all tables?" enhancement closed normal general normal wontfix functional-tests