I want to write a unit test for a Django manage.py command that does a backend operation on a database table. How would I invoke the management command directly from code?
Rather than do the call_command trick, you can run your task by doing:
from myapp.management.commands import my_management_task
cmd = my_management_task.Command()
opts = {} # kwargs for your command -- lets you override stuff for testing...
cmd.handle_noargs(**opts)