Avoid importing django.test
package when not testing by bluetech · Pull Request #8699 · encode/django-rest-framework (original) (raw)
Description
Importing anything from rest_framework
causes django.test
to be imported. This is because DRF registers a receiver on thedjango.test_signals.setting_changed
signal.
This is not really a problem, but it is good to avoid this because it bloats the memory with unnecessary modules (e.g. django.test
, django.core.servers.basehttp
, socketserver
) and increases the startup time. It also doesn't feel right to import test code into non-test code.
Try to import the signal from a core module if possible.
Note that there's another django.test
import in MultiPartRenderer
, however this import is done lazily only if the functionality is used so can be easily avoided.