"finally" for unit test

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Fri Mar 23 12:30:00 CET 2007

On Fri, 23 Mar 2007 04:18:59 -0700, killkolor wrote:

> The problem now is that after each testrun I have to copy "fresh" files
> into the testdirectory, since of course the function already run on all
> the files and made the changes. So I implemented a buffering in the
> unittest functions: buffer the file, call the function, make the test,
> write the buffered file back. This works fine for unittests that do not
> fail. If a unittest fails though the function stops and the writing back
> is never done. Is there something like a finally for unittest functions?
> Or could I use another approach to buffer and write back my files (for
> each unittest function)?

A simple approach would be to copy the test files *before* running the
tests, instead of after. That way it doesn't matter if the tests fail or
not: the next run will simply replace the test files with known good
copies, regardless.


More information about the Python-list mailing list