Avoid importing django.test
package when not testing
#8699
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Importing anything from
rest_framework
causesdjango.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 inMultiPartRenderer
, however this import is done lazily only if the functionality is used so can be easily avoided.