It seems to me that you're trying to address two separate issues:
- Allow tests to run independently (with regard to
MEDIA_ROOT
) when testers do the right thing (i.e. inherit from your test class and call yoursetUp()
). - Keep testers from messing up real data when they accidentally do the wrong thing.
Given that, I think a two-pronged approach makes sense. Your setUp()
solves problem 1. Setting up MEDIA_ROOT
in the test runner, though, hides the fact that your testers have done the wrong thing. Instead I would just focus on protecting the data: for example, you could set MEDIA_ROOT
to None
. That would shield the real data in MEDIA_ROOT
; make it more likely that the tester will see an error if they don't use your setUp()
; and reduce code duplication.
A more robust approach would be to write your own test runner that does the setup before each test (modeled after the way Django handles the database), but that may be overkill for your needs.