Use a context manager to restore state of functional test environment
|Reported by:||Ryan J Ollos||Owned by:|
There is a repeated pattern of
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
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
If we were to take this further, additional things could be done on entry / exit:
- Copy / restore the
permissiontable in the database. Another possibility would be to store all of the calls to
revoke_permand undo the changes.
FunctionalTestEnvironment.enable_authz_permpolicy / disable_authz_permpolicy.
- Copy / restore all tables?