About the Output of a Management Command

You can call a Django management command programmatically with call_command() function. Check its output by passing a StringIO instance as stdout to it:

from io import StringIO
from django.core.management import call_command

output = StringIO()
call_command("mycommand", verbosity=2, stdout=output)
assert("Success!" in output.getvalue())

Tips and Tricks Programming Development Django 5.x Django 4.2 Django 3.2 Python 3