Reputation: 10993
I am using the storages.backends.s3boto.S3BotoStorage
for my DEFAULT_FILE_STORAGE
in a Django project.
Ideally I would like to either use the default FileSystemStorage
during unit tests or perhaps create a temporary bucket that is deleted on the conclusion of the tests.
What is the best way to accomplish this?
Upvotes: 5
Views: 2502
Reputation: 858
I typically keep a separate settings file for tests, test.py
. You can configure the storage backend there, as well as any other settings you want to change during tests. Then, run the tests like this:
python manage.py tests --settings=project.test
The --settings
flag is the dotted path the the settings module you want to use (The default would be project.settings
).
Good optimizations for a test settings file: https://web.archive.org/web/20180204071529/http://www.daveoncode.com/2013/09/23/effective-tdd-tricks-to-speed-up-django-tests-up-to-10x-faster/
Two Scoops of Django is a good place to read about the multi-settings file setup.
Upvotes: 3
Reputation: 16733
First of all, use separate file for testing as pointed out above.
Secondly, there is a python library called moto for mocking and testing botos3.
git repository:- https://github.com/spulec/moto
Upvotes: 2