In airmozilla the tests almost all derive from one base class whose
tearDown deletes the automatically generated
settings.MEDIA_ROOT directory and everything in it.
Then there's some code that makes sure a certain thing from the fixtures has a picture uploaded to it.
That means it has do that
shutil.rmtree(directory) and that
shutil.copy(src, dst) on almost every single test. Some might also not need or depend on it but it's conveninent to put it here.
Anyway, I thought this is all a bit excessive and I could probably optimize that by defining a custom test runner that is first responsible for creating a clean
settings.MEDIA_ROOT with the necessary file in it and secondly, when the test suite ends, it deletes the directory.
But before I write that, let's measure how many gazillion milliseconds this is chewing up.
tearDown was called 361 times and the
_upload_media 281 times. In total, this adds to a whopping total of 0.21 seconds! (of the total of 69.133 seconds it takes to run the whole thing).
I think I'll cancel that optimization idea. Doing some light
shutil operations are dirt cheap.